Advertisement
here2share

# Tk_menu.py

Oct 25th, 2020
2,308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.82 KB | None | 0 0
  1. # Tk_menu.py
  2.  
  3. from tkinter import *
  4. from tkinter import ttk
  5.  
  6. def test(menu_name, items):
  7.     print(menu_name)
  8.     print(items)
  9.  
  10. class items_menu():
  11.     def __init__(self, name):
  12.         menubutton = ttk.Menubutton(text=name)
  13.         menubutton.grid(column=0, row=0, sticky=(N, S, E, W))
  14.         menubutton.menu = Menu(menubutton)
  15.         menubutton["menu"] = menubutton.menu
  16.         dict = {}
  17.         for menu_name in ["Menu A", "Menu B", "Menu C"]:
  18.             dict[menu_name] = Menu(menubutton.menu)
  19.             menubutton.menu.add_cascade(label=menu_name, menu=dict[menu_name])
  20.             for items in ["@: item 1", "@: item 2", "@: item 3"]:
  21.                 items = items.replace('@',menu_name[-1])
  22.                 dict[menu_name].add_command(label=items, command=lambda menu_name=menu_name, items=items: test(menu_name, items))
  23. if __name__ == "__main__":
  24.     win = Tk()
  25.     items_menu("Menu")
  26.     win.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement