Retrieval of widget property values
Peter Otten
__peter__ at web.de
Thu Oct 28 05:19:55 EDT 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.
After
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
size_var.get()
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()
12345
Peter
More information about the Python-list
mailing list