Tkinter IntVar returns PY_VAR0 instead of value

I have a Checkbutton object associated with it and IntVar, but when I try to get the value var, I get PY_VAR0.

Here is my code:

from tkinter import *

root = Tk()

def show_state():
    print(var)

var = IntVar()

cbtn = Checkbutton(root, text='Check', variable=var, command=show_state)
cbtn.pack()

root.mainloop()

Why am I getting PY_VAR0?

+4
source share
1 answer

varis a reference to an object Tkinter.IntVar. You need to call a method getto access the value that it represents:

print(var.get())
+8
source

Source: https://habr.com/ru/post/1548554/


All Articles