16014

Text box not shown in GUI

Question:

If you see these lines of code:

L1 = Label(root, text="Time Input") L1.pack( side = LEFT) E1 = Entry(root,bd = 5) E1.pack

I have written a few line of codes for a text input but nothing was shown. I tried many ways but couldn't get it.

Here is my full code:

label = Label(root) label.pack(side = RIGHT) from Tkinter import * from tkFileDialog import askopenfilename root = Tk() root.geometry("400x400") f = Frame(root) #f.pack_propagate(0) # don't shrink f.pack() bottomframe = Frame(root) bottomframe.pack( side = BOTTOM ) scrollbar = Scrollbar(root) scrollbar.pack( side = RIGHT, fill=Y ) def callback(): r = open(askopenfilename(),'r') def sel(): selection = "You have selected " + str(v.get()) label.config(text= selection) a = Button( f,text='Choose File(Audio or Video)', fg="Blue",command=callback) ##b = Button(text='click me', command=callback) a.pack(padx=10, pady=10, side=LEFT) ##b.pack() ##redbutton = Button(f, text="Red", fg="red") ##redbutton.pack( side = LEFT) ## ##greenbutton = Button(f, text="Brown", fg="brown") ##greenbutton.pack( side = LEFT ) ## ##bluebutton = Button(f, text="Blue", fg="blue") ##bluebutton.pack( side = LEFT ) ## ##blackbutton = Button(bottomframe, text="Black", fg="black") ##blackbutton.pack( side = BOTTOM) v = StringVar() R1 = Radiobutton(root, text="G", variable=v, value="G", command=sel) R1.pack( anchor = W ) R2 = Radiobutton(root, text="PG", variable=v, value="PG", command=sel) R2.pack( anchor = W ) R3 = Radiobutton(root, text="NC16", variable=v, value="NC16", command=sel) R3.pack( anchor = W ) R4 = Radiobutton(root, text="M18", variable=v, value="M18", command=sel) R4.pack( anchor = W ) R5 = Radiobutton(root, text="R21", variable=v, value="R21", command=sel) R5.pack( anchor = W ) L1 = Label(root, text="Time Input") L1.pack( side = LEFT) E1 = Entry(root,bd = 5) E1.pack label = Label(root) label.pack(side = RIGHT) R1.select() root.mainloop()

Answer1:

You forgot to call the pack method of E1 by placing () after it:

E1.pack()

Without this change, the entrybox will never be placed on the window.

Recommend

  • retrieve from database dynamically to tkinter gui
  • Group array based on key
  • Center image inside a div like setting background position
  • tkinter: change image in window to random image from variable
  • 'Tk' is not defined [duplicate]
  • Dropzone Resize Function
  • Python Turtle Module- Saving an image
  • Positioning Button in Python
  • Index of same values in Tkinter Optionmenu widget
  • Displaying emojis/symbols in Python using tkinter lib
  • Seven segment display in Tkinter
  • How to update a label in Tkinter, StringVar() not working
  • Python3 ImportError: No module named '_tkinter' on Ubuntu
  • Showing Tkinter window larger than desktop
  • Return values of Tkinter text entry, close GUI
  • Python. Error using animation.FuncAnimation
  • Threads and Tkinter not working together
  • how to assign hotkeys?
  • how to change the div background image in mouse over [duplicate]
  • Sending a variable with a button-command (python 3.3 / tkinter) [duplicate]
  • Passing extra arguments with Tkinter Bindings
  • Python 2.x or 3.x on a Chromebook
  • Highlighting a clicked line in an unfocused Tkinter text widget
  • Status of shift and caps lock in Python
  • Deserializing JSON to a .net base class with JSON.net
  • How to show matplotlib plot from a figure object
  • Tkinter nested mainloop
  • Python : How to center Label in tkinter window
  • What does this mean? (Google Maps API)
  • why isn't the natural height of a Frame updated immediately?
  • Removing Duplicate Geometries
  • as3-flash: any way to access all the instances placed in different frames from document class?
  • wxPython: displaying multiple widgets in same frame
  • R - Combining Columns to String Based on Logical Match
  • Why winpcap requires both .lib and .dll to run?
  • Return words with double consecutive letters
  • Python: how to group similar lists together in a list of lists?
  • embed rChart in Markdown
  • Busy indicator not showing up in wpf window [duplicate]
  • Unable to use reactive element in my shiny app