I've been trying to learn Tkinter and i've stumbled upon the below code while looking up Menu widget.
from tkinter import *
import tkinter.messagebox
top = Tk()
mb= Menubutton ( top, text="condiments", relief=RAISED )
mb.grid()
mb.menu = Menu ( mb, tearoff = 0)
mb["menu"] = mb.menu
mayoVar = IntVar()
ketchVar = IntVar()
mb.menu.add_checkbutton ( label="mayo",
variable=mayoVar )
mb.menu.add_checkbutton ( label="ketchup",
variable=ketchVar )
mb.pack()
top.mainloop()
Now i undertand the purpose of code but am having a hard time figuring out what the below line of code is for.
mb["menu"] = mb.menu
(and)- see PEP 8 -- Style Guide for Python Codemb["menu"]ans see what's happen.mb["menu"] = Menu()assignsMenu IDtoMenubutton- so Menubutton knows what to display.mb.menu = ...doesn't assignMenutoMenubuttonand you can use any other variable ie.submenuinstead ofmb.menu