Python Forum

Full Version: Checkbox half working
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I will. But trying it one step at a time. Can't get the 1 in the list yet. When I get that solved, then replacing it with a 0 should be easy.
Instead of having a callback for the checkbox and a list for saving the checkbox state, why don't you just use the tkinter variable? The code below makes 8 checkboxes and collects all their state when some other even (in this case a button press) occurs.
from tkinter import *

def complete_form():
    for i, var in enumerate(scratched):
        print(i, var.get())
 
root = Tk()
scratched = []
for i in range(8):
    var = BooleanVar()
    scratched.append(var)
    button = Checkbutton(root, text = str(i),
        variable = var, onvalue = True, offvalue = False)
    button.grid(row=i, column=0)

button = Button(root, text = "Accept", command=complete_form)
button.grid(row=8, column=0)
mainloop()
Output:
0 True 1 False 2 False 3 True 4 False 5 False 6 False 7 True
Thank you so much Dean. I truly appreciate the help. I will in fact do it your way. Awesome. Program logic is a weakness of mine for sure.

Thanks Again.
Pages: 1 2