Drop down menu using button with image in tkinter

Viewed 491

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

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.

Related