user13053218
user13053218

Reputation:

Python tkinter drop down menu

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

Answers (4)

Lucian Chauvin
Lucian Chauvin

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

Ashish kumar
Ashish kumar

Reputation: 11

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

Upvotes: 1

Paties
Paties

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

Thomas
Thomas

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

Related Questions