-
Notifications
You must be signed in to change notification settings - Fork 1
/
menus.py
30 lines (26 loc) · 876 Bytes
/
menus.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from tkinter import *
root= Tk()
def my_function():
print("Hello World!")
# Non-Drop Down
menu = Menu(root)
menu.add_command(label="File", command=my_function)
menu.add_command(label="Quit", command=quit)
root.config(menu=menu)
# Drop Down
main_menu = Menu(root)
# tearoff use to fix the menu
sub_menu1 = Menu(main_menu, tearoff=0)
sub_menu1.add_command(label="New", command=my_function)
# for seprating in menus
sub_menu1.add_separator()
sub_menu1.add_command(label="Quit", command=quit)
root.config(menu=main_menu)
main_menu.add_cascade(label="File", menu=sub_menu1)
sub_menu2 = Menu(main_menu, tearoff=0)
sub_menu2.add_command(label="Test1", command=my_function)
sub_menu2.add_separator()
sub_menu2.add_command(label="Quit", command=quit)
root.config(menu=main_menu)
main_menu.add_cascade(label="Test", menu=sub_menu2)
root.mainloop()