【发布时间】:2020-09-08 13:20:56
【问题描述】:
我正在尝试在 Tkinter 中打印复选框的布尔值,我创建了一个类似于我的原始代码的最小复制示例。
可能看起来不需要线程,但我的实际项目需要它。
无论如何,我只是想访问checkbutton_gen类的每个实例的复选框变量
代码如下:
import threading
from tkinter import *
root = Tk()
class checkbutton_gen(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.checkbuttonvalue = BooleanVar(value=False)
def run(self):
self.checkbutton = Checkbutton(root,onvalue=True,offvalue=False,textvariable=self.checkbuttonvalue)
self.checkbutton.pack()
for count in range(10):
thread = checkbutton_gen()
thread.start()
Button(root, text='Check to see of checkboxes are ticked', command=lambda:check()).pack()
def check():
for checkbox in checkbutton_gen.checkbuttonvalue:
print(checkbutton_gen.checkbuttonvalue)
root.mainloop()
这是我得到的错误:
for checkbox in checkbutton_gen.checkbuttonvalue:
AttributeError: type object 'checkbutton_gen' has no attribute 'checkbuttonvalue'
【问题讨论】:
标签: python multithreading tkinter checkbox