I'm trying to create a dropdown menu using the button with images and I will put some functions on each button, but on the drop-down menu that I use the only button that is available to use is a check button. this is the program that I'm currently using.
from tkinter import *
root = Tk()
mbtn = Menubutton(root, text="Options", relief=RAISED)
mbtn.menu = Menu(mbtn, tearoff = 0)
mbtn["menu"] = mbtn.menu
mbtn.menu.add_checkbutton(label="Outing")
mbtn.menu.add_checkbutton(label="Sleep")
mbtn.menu.add_checkbutton(label="Tour")
mbtn.pack()
root.mainloop()
Does this solve Your issue?
from tkinter import *
root = Tk()
mbtn = Menubutton(root, text="Options", relief=RAISED)
mbtn.pack()
mbtn.menu = Menu(mbtn, tearoff = 0)
mbtn["menu"] = mbtn.menu
mbtn.menu.add_checkbutton(label="Outing")
mbtn.menu.add_checkbutton(label="Sleep")
mbtn.menu.add_checkbutton(label="Tour")
root.mainloop()
instead of mbtn.pack()
You can obviously also use mbtn.grid()
or mbtn.place()
(not suggested - .place()
)
@TheLizzard added: You can use root.config(menu=mbtn.menu)
(instead of mbtn.pack()
) to make the menu part of the window.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.