Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tkinter IntVar returning PY_VAR0 instead of value

Tags:

People also ask

How can I get IntVar value?

Retrieving Values Of IntVar() Variables We can use get() method on IntVar() variable to retrieve the text value present in the variable.

How do I use IntVar in Python?

x = IntVar() # Holds an integer; default value 0. x = DoubleVar() # Holds a float; default value 0.0. x = BooleanVar() # Holds a boolean, returns 0 for False and 1 for True.

What is the difference between a variable and StringVar () in Tkinter?

A normal variable can be used to set the value for any application whenever it is required. However, we can take the user input by creating an instance of the StringVar() object.

What does TK StringVar () do?

The Tkinter StringVar helps you manage the value of a widget such as a Label or Entry more effectively. The StringVar constructor accepts three optional arguments: container is a widget that the StringVar object associated with. If you skip the container, it defaults to the root window.


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

Here's 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?


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!