Apr-04-2020, 02:54 AM
(This post was last modified: Apr-04-2020, 02:54 AM by deanhystad.)
I don't think you are supposed to set or get values from the widget. It looks like you ttk expects you to create a variable and bind it to the control. Changes to the value change the appearance of the control, and manipulating the control changes the value of the variable. In the example below I make two columns of checkbuttons. Each row shares the same variable, so changing one check box changes the other. At the bottom are a couple of buttons for checking/unchecking all the buttons. None of these operation use the widget directly which I toss away as soon as it is added to the form.
from functools import partial from tkinter import * from tkinter.ttk import * window = Tk() window.title = 'Checkbuttons' variables = [] def set_all(value): for v in variables: v.set(value) for i in range(1, 5): v = BooleanVar() variables.append(v) Checkbutton(window, text='Check button'+str(i), variable=v).grid(column=0, row=i) Checkbutton(window, text='Check button'+str(i+4), variable=v).grid(column=1, row=i) Button(window, text='Check All', command = partial(set_all, True)).grid(column=0, row=6) Button(window, text='Uncheck All', command = partial(set_all, False)).grid(column=1, row=6) window.mainloop()If you are planning on writing GUI applications in python you should experiment with using pakages other than Tk/tkinter/ttk. I played with Tk a little bit before moving on to wxPython and now PySide2. I've also used GTK outside of python. Of those I liked Tk the least by a wide margin.