Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_menu.py
- from tkinter import *
- from tkinter import ttk
- def test(menu_name, items):
- print(menu_name)
- print(items)
- class items_menu():
- def __init__(self, name):
- menubutton = ttk.Menubutton(text=name)
- menubutton.grid(column=0, row=0, sticky=(N, S, E, W))
- menubutton.menu = Menu(menubutton)
- menubutton["menu"] = menubutton.menu
- dict = {}
- for menu_name in ["Menu A", "Menu B", "Menu C"]:
- dict[menu_name] = Menu(menubutton.menu)
- menubutton.menu.add_cascade(label=menu_name, menu=dict[menu_name])
- for items in ["@: item 1", "@: item 2", "@: item 3"]:
- items = items.replace('@',menu_name[-1])
- dict[menu_name].add_command(label=items, command=lambda menu_name=menu_name, items=items: test(menu_name, items))
- if __name__ == "__main__":
- win = Tk()
- items_menu("Menu")
- win.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement