Skip to content

Commit 4b31743

Browse files
author
Mofan Zhou
committed
create tk9
1 parent c9e95f1 commit 4b31743

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

tkinterTUT/tk9_menubar.py

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# View more python learning tutorial on my Youtube and Youku channel!!!
2+
3+
# Youtube video tutorial: https://www.youtube.com/channel/UCdyjiB5H8Pu7aDTNVXTTpcg
4+
# Youku video tutorial: http://i.youku.com/pythontutorial
5+
6+
import tkinter as tk
7+
8+
window = tk.Tk()
9+
window.title('my window')
10+
window.geometry('200x200')
11+
12+
l = tk.Label(window, text='', bg='yellow')
13+
l.pack()
14+
counter = 0
15+
def do_job():
16+
global counter
17+
l.config(text='do '+ str(counter))
18+
counter+=1
19+
20+
menubar = tk.Menu(window)
21+
filemenu = tk.Menu(menubar, tearoff=0)
22+
menubar.add_cascade(label='File', menu=filemenu)
23+
filemenu.add_command(label='New', command=do_job)
24+
filemenu.add_command(label='Open', command=do_job)
25+
filemenu.add_command(label='Save', command=do_job)
26+
filemenu.add_separator()
27+
filemenu.add_command(label='Exit', command=window.quit)
28+
29+
editmenu = tk.Menu(menubar, tearoff=0)
30+
menubar.add_cascade(label='Edit', menu=editmenu)
31+
editmenu.add_command(label='Cut', command=do_job)
32+
editmenu.add_command(label='Copy', command=do_job)
33+
editmenu.add_command(label='Paste', command=do_job)
34+
35+
window.config(menu=menubar)
36+
37+
window.mainloop()
38+
39+

0 commit comments

Comments
 (0)