- Tkinter GUI Application Development Cookbook
- Alejandro Rodas de Paz
- 75字
- 2021-08-27 19:44:04
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:

推薦閱讀
- Getting Started with Gulp(Second Edition)
- Hands-On Machine Learning with scikit:learn and Scientific Python Toolkits
- 區塊鏈架構與實現:Cosmos詳解
- 數據庫系統原理及MySQL應用教程
- HTML5入門經典
- concrete5 Cookbook
- Apache Spark 2.x for Java Developers
- FPGA嵌入式項目開發實戰
- 原型設計:打造成功產品的實用方法及實踐
- Getting Started with hapi.js
- Isomorphic Go
- VMware vSphere Design Essentials
- Beginning PHP
- Swift 2 Blueprints
- Yii框架深度剖析