Tkinter Gui Problems
Solution 1:
from Tkinter import *
root = Tk()
menu = Menu(root)
root.config(menu=menu)
filemenu = Menu(menu)
my_label = Label(root, text="Select Menu")
my_label.place(x=10,y=10)
defmy_command(query):
my_label.config(text=query)
menu.add_cascade(label="File", menu=filemenu)
filemenu.add_command(label="New", command=lambda x = "New":my_command(x))
filemenu.add_command(label="Open...", command=lambda x = "Open...":my_command(x))
filemenu.add_separator()
filemenu.add_command(label="Exit", command=root.destroy)
helpmenu = Menu(menu)
menu.add_cascade(label="Help", menu=helpmenu)
helpmenu.add_command(label="About...", command=lambda x = "About...":my_command(x))
body = Label(root, text="")
mainloop()
@Lafexlos is correct.
You can use all python types(list,dict,var and more...) on GUI
design, most important point how to manage all GUI elements
, so all need an accessible status.
Don't destroy
any GUI element, change and reuse it.
Don't include any external command to mainloop
(like:file,network, etc.)
All GUI application required 3 critical section : INIT >> BUILD >> RUN
Otherwise you got a lot painful.
Use GUI elements text
as variable
, of-course if all element is accesible !
I hope helpful and accept @Lafexlos answer not my ! This code work on Python2.7
Solution 2:
You are not using geometry managers(pack/grid/place) on your widgets so tkinter doesn't show those to you.
Also, instead of creating new labels on every click, you can either create all three in global scope and pack&forget on clicks or just create one Label and change its value depending on your needs.
Post a Comment for "Tkinter Gui Problems"