Skip to content

Commit e597953

Browse files
author
Mofan Zhou
committed
create tk7
1 parent 2fc0243 commit e597953

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

tkinterTUT/tk7_checkbutton.py

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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, bg='yellow', width=20, text='empty')
13+
l.pack()
14+
15+
def print_selection():
16+
if (var1.get() == 1) & (var2.get() == 0):
17+
l.config(text='I love only Python ')
18+
elif (var1.get() == 0) & (var2.get() == 1):
19+
l.config(text='I love only C++')
20+
elif (var1.get() == 0) & (var2.get() == 0):
21+
l.config(text='I do not love either')
22+
else:
23+
l.config(text='I love both')
24+
25+
var1 = tk.IntVar()
26+
var2 = tk.IntVar()
27+
c1 = tk.Checkbutton(window, text='Python', variable=var1, onvalue=1, offvalue=0,
28+
command=print_selection)
29+
c2 = tk.Checkbutton(window, text='C++', variable=var2, onvalue=1, offvalue=0,
30+
command=print_selection)
31+
c1.pack()
32+
c2.pack()
33+
34+
35+
window.mainloop()
36+

0 commit comments

Comments
 (0)