[Tutor] help with .get in Tkinter
klappnase at freenet.de
Sun Feb 20 17:11:05 CET 2005
On Sun, 20 Feb 2005 17:12:54 +0200
Mark Kels <mark.kels at gmail.com> wrote:
> Hi all.
> First, here is the code I have a problem with (I got same problem in
> my project) :
> from Tkinter import *
> def go():
> print e
> For some reason the function is called before I click the button, and
> I get .10037088 before I have done a thing.
> How do I do it right ???
you need to assign the command for the button without parenthesis:
b = Button(main, text='OK', command=go)
I split the line you used into two lines, because pack() returns None , so you don't have a reference
to the button once you created it. Of course you can do it the way you did if you don't need to reference
the button anymore, however there's not much use in assigning a new variable to it, just write:
your go() function does just what you told it to: it prints the "window name" (or however this is called) of
the entry widget. You surely meant something like this:
contents = e.get()
I hope this helps
More information about the Tutor