1
x = tk.IntVar()
def test():
   print(x.get())
checkBox = tk.Checkbutton(text="test",command=test(),variable=x)
checkBox.grid(row=12,column=2)

b=tk.Button(text="test",command=test)
b.grid(row=12,column=0

this is some code I put in my program for testing, when I check the checkbox the value does change (I can confirm it with the button I made to test) but the command does not get executed.

UCSA
  • 33
  • 9

1 Answers1

1

Remove () in command

command= test

This works fine:

import tkinter as tk

win = tk.Tk()
x = tk.IntVar()


def test():
    print(x.get())


checkBox = tk.Checkbutton(text="test", command=test, variable=x)
checkBox.grid(row=12, column=2)
win.mainloop()
Shamshirsaz.Navid
  • 2,224
  • 3
  • 22
  • 36