lundi 9 mai 2022

Tkinter get checkbuttons checked

I am new to Tkinter trying to get the value of the checked checkbuttons. So far, I am able to use a loop on Checkbutton in order to get a list of available check buttons from a list. How can I use a button to detect which of the check buttons are checked?

This is my code so far (for this part):

INGREDIENTS = ['cheese', 'ham', 'pickle', 'mustard', 'lettuce']
text = Text(root, width=40, height=20)
for i in INGREDIENTS:
    cb = Checkbutton(text="%s" % i, padx=0, pady=0, bd=0)
    text.window_create("end", window=cb)
    text.insert("end", "\n")
    cb.pack()

I know I have to use a button connected to a function in order to get the checked values, but I cannot think of a way to create the function and connect it to the list of check boxes.

Can you help me please? I can't use OOP, my code would be ruined (it is already long and I cannot reformat it all)

Thank you in advice.




Aucun commentaire:

Enregistrer un commentaire