Jul-07-2020, 04:44 AM
state does not do what you think it does. state is used for styling a ttk widget. You use "selected" in combination with "state" to specify how a widget should appear when selected.
The way to get and set the value of ttk.Checkbutton is use tkinter variables.
The way to get and set the value of ttk.Checkbutton is use tkinter variables.
from tkinter import * from tkinter import ttk mw = Tk() mw.geometry('700x300+400+200') frame3 = Frame(mw) framebot = Frame(mw) frame3.pack(side=TOP,fill=X) framebot.pack(side=BOTTOM,fill=X) w3 = Label(frame3, text="Checkbuttons: ",font=("Times",16)).grid(row=0,column=0) check_buttons = [] for i in range(1, 7): value = BooleanVar() button = ttk.Checkbutton(frame3, text=str(i), variable=value) check_buttons.append(value) value.set(i % 2 == 0) button.grid(row=i,column=0) mw.mainloop()