I would like to get status of all defined checkbuttons by "for" function. I have four checkbuttons and output is (off, off, off, off):
[0, 0, 0, 0]
But I need to have for example (off, on, on, off):
[0, 1, 1, 0]
It looks like below code is geeting only staus from last "D" checkbuton and append to "buttons_status" list.
Any idea how to get status of all chcekbuttons? Thanks in advance.
Here is a code:
from tkinter import *
names = ['A','B','C','D']
buttons_status = []
root = Tk()
for x in range(0,len(names)):
checkbutton_input = IntVar()
checkbutton = Checkbutton(root, text=str(names[x]),
variable=checkbutton_input)
checkbutton.grid(row=3, column=x)
status = checkbutton_input.get()
buttons_status.append(status)
root.mainloop()
print(buttons_status)