官术网_书友最值得收藏!

How to do it...

The following application shows how to create Checkbutton, which must be connected to an IntVar variable to be able to inspect the button state:

import tkinter as tk

class SwitchApp(tk.Tk):
    def __init__(self):
        super().__init__() 
        self.var = tk.IntVar() 
        self.cb = tk.Checkbutton(self, text="Active?",  
                                 variable=self.var, 
                                 command=self.print_value) 
        self.cb.pack() 
 
    def print_value(self): 
        print(self.var.get()) 
 
if __name__ == "__main__": 
    app = SwitchApp() 
    app.mainloop() 

In the preceding code, we simply printed the value of the widget each time it is clicked:

主站蜘蛛池模板: 山阴县| 阳信县| 海阳市| 田林县| 平罗县| 宜春市| 定兴县| 肥西县| 昌乐县| 郎溪县| 枞阳县| 杭州市| 海林市| 鹤岗市| 博兴县| 公主岭市| 香河县| 化德县| 贵德县| 咸阳市| 浠水县| 彭山县| 壶关县| 龙泉市| 碌曲县| 桓台县| 彩票| 湖南省| 沙河市| 大埔县| 怀远县| 始兴县| 盘山县| 犍为县| 淮安市| 茶陵县| 阿拉善右旗| 玉屏| 奉新县| 扶沟县| 梧州市|