Retrieval of widget property values

Peter Otten __peter__ at
Thu Oct 28 11:19:55 CEST 2010

Alex wrote:

> thanks Peter,
> I'm probably not getting something, but how do show_size and
> show_button account for the changes in Entry? There are no references
> to the widget in either the function of the button. Sorry if the
> question is too dumb.


size_var = IntVar()
size_entry = Entry(..., textvariable=size_var)

Tkinter automatically synchronizes the value in the Entry with that in the 
IntVar. Therefore you can read the value shown in the Entry widget with


Perhaps it becomes clearer in an interactive session:

>>> from Tkinter import *
>>> root = Tk()
>>> size_var = IntVar()
>>> size_entry = Entry(root, textvariable=size_var)
>>> size_entry.pack()
>>> size_var.set(42)

The Entry widget should show 42 now instead of the initial 0. Type 12345 
into the widget, then go back to the shell:

>>> size_var.get()


More information about the Python-list mailing list