using get() with Entry()

Steve Holden sholden at holdenweb.com
Fri Apr 19 22:04:42 EDT 2002


"Eric Brake" <ebrake2002 at yahoo.com> wrote in message
news:12f756b9.0204191747.7acb2b74 at posting.google.com...
> I've looked through all of the documentation I can find. I can't make
> get() work with Entry().
>
> Here's my code:
> ###
> guess = StringVar()
> guessbox = 0
> guessbox= Entry(root, width=20, textvariable=guess).pack()
> guess.set(guessbox.get(guessbox))
> ###
>
> It keeps giving me a error message saying:
> Traceback (most recent call last):
>   File "D:\My Documents\mymodules\gui\guessthenumber.py", line 43, in
> ?
>     guess.set(guessbox.get(guessbox))
> AttributeError: 'NoneType' object has no attribute 'get'
>
> What am I not doing? I just now learning this so break it down,
> Please.
> Thank you for your help

It's a while since I used Tkinter, but isn't the point of associating a
textvariable with the Entry widget to make it unnecessary to synchronize the
contents yourself?

Therefore, I should have thought your last line should have been something
like

    mystring = guess.get()

Tkinter itself handles the updaying of the StringVar's value for you, you
just pull the value out. You can also use its set() method to put a value in
to the TextEntry. A Google search for "python tkinter stringvar" yields
David Mertz' useful page

    http://www-106.ibm.com/developerworks/library/l-tkprg/

Find "stringvar" in that and you're almost home.

I agree it's annoying that Fredrik Lundh didn't complete the public version
of his Tkinter reference manual. I'd complain, except that he's done far
more for the Python system than I'm ever likely to...

regards
 Steve
--
home: http://www.holdenweb.com/    book: http://pydish.holdenweb.com/pwp/







More information about the Python-list mailing list