I'm trying to print the boolean value of check boxes in Tkinter, I've created a minimal reproduced example that resembles my original code.
It may look like threading is not needed, but it is needed for my actual project.
Anyway I'm just trying to access the checkbox variable for each instance of class checkbutton_gen
Here's the code:
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()
Here's the error i'm getting:
for checkbox in checkbutton_gen.checkbuttonvalue:
AttributeError: type object 'checkbutton_gen' has no attribute 'checkbuttonvalue'
Aucun commentaire:
Enregistrer un commentaire