python - 无法为 tkinter 复选框设置默认值
问题描述
我正在尝试使用默认值创建复选框True
,但它不起作用,我尝试了很多答案但没有奏效
import tkinter as tk
class App(tk.Tk):
def __init__(self):
super().__init__()
self.title("Test v1")
self.geometry("400x250")
self.build_init()
def build_init(self):
#CheckVar = tk.BooleanVar(self,)
CheckVar = tk.IntVar(value=1)
checkbutton = tk.Checkbutton(self, text = "Test", variable = CheckVar,onvalue=1, offvalue=0)
#checkbutton.select()
checkbutton.place(x=20,y=80)
App().mainloop()
select
除了哪些不起作用之外,我在文档中找不到太多关于它的内容,还有关于这个问题Tkinter: 有没有办法默认检查复选框?
解决方案
import tkinter as tk
class App(tk.Tk):
def __init__(self):
super().__init__()
self.title("Test v1")
self.geometry("400x250")
self.build_init()
def build_init(self):
#CheckVar = tk.BooleanVar(self,)
self.CheckVar = tk.IntVar(value=1)
self.checkbutton = tk.Checkbutton(self, text = "Test", variable = self.CheckVar,onvalue=1, offvalue=0)
#checkbutton.select()
self.checkbutton.place(x=20,y=80)
App().mainloop()
推荐阅读
- firebase - 您可以在尚未构建的移动应用上使用 Firebase 吗?
- java - 如何找到一组最佳整数/协调器,其中第一个坐标和最后一个坐标之间的距离可能是最小的?
- ietf-netmod-yang - 杨模型强制节点仅在条件为真时
- javascript - navigator.clipboard.writeText() 不适用于特定的 IOS 设备
- android - 我有一个关于在 Flutter 中使用 Shared_Preferences 的问题
- configuration - How to upload my servers on virtual machine?
- cuda - 在 cuda 中,哪个线程负责内核内请求的共享内存分配?
- java - Java Swing - 显示玻璃窗格并使用事件而不会失去以前的焦点所有者
- r - 使用 R 进行线性回归:如何在 qq 图中的数据点上获得标签、比例位置图、残差与杠杆等
- sqlite - sqlite - 使用单个查询查找表中是否存在多条记录