I want to create a list of checkboxes in Python with TkInter and try to select all checkboxes with a button.
from tkinter import *
def create_cbuts():
for i in cbuts_text:
cbuts.append(Checkbutton(root, text = i).pack())
def select_all():
for j in cbuts:
j.select()
root = Tk()
cbuts_text = ['a','b','c','d']
cbuts = []
create_cbuts()
Button(root, text = 'all', command = select_all()).pack()
mainloop()
I fear that he does not fill the list cbuts:
cbuts.append(Checkbutton(root, text = i).pack())
Replace:
with:
Checkbutton(root, text = i).pack()returns youNone. So you are actually appendingNones to your list. What you need to do is: append the instance ofButtonnot the value which.pack()returns (None)