Tkinter select all Checkbuttons
14:14 20 Feb 2026
import tkinter as tk
from tkinter import ttk

def select_all(event):
    checkbutton_1_int.set(not checkbutton_all_int.get())
    checkbutton_2_int.set(not checkbutton_all_int.get())
    checkbutton_3_int.set(not checkbutton_all_int.get())
    checkbutton_4_int.set(not checkbutton_all_int.get())

def unselect_all(event):
    if checkbutton_1_int.get() == 0 or checkbutton_1_int.get() == 0:
        checkbutton_all_int.set(0)
    if checkbutton_1_int.get() == 1 and checkbutton_1_int.get() == 1:
        checkbutton_all_int.set(1)

root = tk.Tk()

root.geometry("300x300")

checkbutton_all_int = tk.IntVar()
checkbutton_all_int.set(0)
checkbutton_1_int = tk.IntVar()
checkbutton_1_int.set(0)
checkbutton_2_int = tk.IntVar()
checkbutton_2_int.set(0)
checkbutton_3_int = tk.IntVar()
checkbutton_3_int.set(0)
checkbutton_4_int = tk.IntVar()
checkbutton_4_int.set(0)

checkbutton_all = ttk.Checkbutton(text="all",variable=checkbutton_all_int, onvalue=1, offvalue=0)
checkbutton_1 = ttk.Checkbutton(text="1",variable=checkbutton_1_int, onvalue=1, offvalue=0)
checkbutton_2 = ttk.Checkbutton(text="2",variable=checkbutton_2_int, onvalue=1, offvalue=0)
checkbutton_3 = ttk.Checkbutton(text="3",variable=checkbutton_3_int, onvalue=1, offvalue=0)
checkbutton_4 = ttk.Checkbutton(text="4",variable=checkbutton_4_int, onvalue=1, offvalue=0)

checkbutton_all.pack()
checkbutton_1.pack()
checkbutton_2.pack()
checkbutton_3.pack()
checkbutton_4.pack()

checkbutton_all.bind("",select_all)
checkbutton_1.bind("",unselect_all)
checkbutton_2.bind("",unselect_all)
checkbutton_3.bind("",unselect_all)
checkbutton_4.bind("",unselect_all)

root.mainloop()

How can I make it so that when I uncheck 1, 2, 3, or 4 that all button is also unchecked?
I don't get it why it unchecks the button all when I deactivate and activate button 1 (or any other) again.
It seems to me as if the current check button value is always one behind.

python tkinter