Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Checkbox half working
#11
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.
Reply
#12
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
Reply
#13
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Checkbox itens with a button to run action Woogmoog 3 945 Dec-19-2022, 11:54 AM
Last Post: Woogmoog
  Use String contents for checkbox name jcday 1 1,622 Dec-06-2019, 06:01 PM
Last Post: Larz60+
  How to run a loop till half of the string...without using inbuilt function krish 1 2,912 Sep-28-2017, 05:34 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020