Reputation:
I am programming a menu into my first python tkinter menu window. I have done it all right (I think) but the menu doesn't appear on my tkinter window.
My code is:
from tkinter import *
def f1():
label = Label(window, text="Wassup CHUNGUS!!!")
label.grid(row=0, column=0, sticky=W)
global window
window = Tk()
window.title("CHUNGUS")
label2 = Label(window, text="!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
label2.grid(row=2, column=0, sticky=W)
menubar = Menu(window)
firstmenu = Menu(menubar, tearoff=0)
firstmenu.add_command(label="EXIT", command=window.destroy)
firstmenu.add_command(label="CHUNGUS", command =f1)
menubar.add_cascade(label="Menu", menu=firstmenu)
window.mainloop()
Can I have some help?
Upvotes: 1
Views: 1703
Reputation: 82
The simplest way to achieve a drop-down list within Tkinter is to use the OptionMenu widget built into tkinter.
from Tkinter import *
master = Tk()
variable = StringVar(master)
variable.set("one") # default value
w = OptionMenu(master, variable, "one", "two", "three")
w.pack()
mainloop()
Upvotes: 0
Reputation: 11
Just put the code window.config(menu=menubar)
before window.mainloop()
Upvotes: 1
Reputation: 47
you forgot to config the code to menu if you understand window.config(menu=menubar)
and also a tip ig in this code you don't need global window if for this code im sayin
Upvotes: 0
Reputation: 1212
This is quite easy. You have not included window.config(menu=menubar)
. You should put it before the window.mainloop()
so:
window.config(menu=menubar)
window.mainloop()
Upvotes: 2