Q:

Checkbutton on tkinter retains it's value no matter what

I'm trying to get the value from Checkbutton on tkinter but it retains the original value. I have tried what people say on countless forums including this one but nothing works, it just retains the value i give it with var.set(True) or var.set(False). This chechbutton is on a pop up window btw, but it's not global, it's just defined on said window. this is my code:
import tkinter as tk 
import tkinter.ttk as ttk

root = tk.Tk()
root.geometry('500x500')

var = tk.BooleanVar()
var.set(False)
startup = tk.Checkbutton(root, variable=var, onvalue=True, offvalue=False , text = "test")

when ver i use var.get() i get the initial value. help me plz :( Thanks in advice.

A:

The reason is because Checkbutton requires a callback function to change the state of the button.
def toggle(button):
    if button.get() is True:
        button.set(True)
    else:
        button.set(False)

The you would use the callback function in the instantiation of the Checkbutton
startup = tk.Checkbutton(root, variable=var, text = "test",
            command=lambda button=var: toggle(button))

