1

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?

4 Answers 4

2

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()
Sign up to request clarification or add additional context in comments.

3 Comments

I would advise putting it before the window.mainloop()... This implies that you could place it after the mainloop but is just better to put it before for some reason. In reality you have no choice but to put it before the main loop. I would update that sentence.
Agree. mainloop() blocks until one stops or exits
Ok. I changed it
1

Just put the code window.config(menu=menubar) before window.mainloop()

Comments

0

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

Comments

0

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()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.