/
tk_test09_checkbutton.py
56 lines (36 loc) · 1.04 KB
/
tk_test09_checkbutton.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/python3
# -*- coding: utf-8 -*-
"""
ZetCode Tkinter tutorial
This program toggles the title of the
window with the Checkbutton widget.
Author: Jan Bodnar
Last modified: July 2017
Website: www.zetcode.com
"""
from tkinter import Tk, Frame, Checkbutton
from tkinter import BooleanVar, BOTH
class Example(Frame):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.master.title("Checkbutton")
self.pack(fill=BOTH, expand=True)
self.var = BooleanVar()
cb = Checkbutton(self, text="Show title",
variable=self.var, command=self.onClick)
cb.select()
cb.place(x=50, y=50)
def onClick(self):
if self.var.get() == True:
self.master.title("Checkbutton")
else:
self.master.title("")
def main():
root = Tk()
root.geometry("250x150+300+300")
app = Example()
root.mainloop()
if __name__ == '__main__':
main()