get() in Tkinter

Matthew Dixon Cowles matt at mondoinfo.com
Fri Aug 30 22:03:28 EDT 2002


On Fri, 30 Aug 2002 21:08:05 -0400, Andrew M
<stopviequesbombing at hotmail.com> wrote:

[. . .]

> from Tkinter import *
> 
> # ---interface part cut out---
> 
> def changetext():
>         a = str(Entry.get(entrybox1))
>         b = a + " ....continue"
>         Entry.insert(b)
> 
> I know this doesn't work, and I think it is the Entry.Insert line.

Dear Andrew,
You're right that it's the insert call that's the problem. You have to
call insert() with an index. And it turns out to be necessary to
delete the previous text first. Something like this:

>>> from Tkinter import *
>>> r=Tk()
>>> e=Entry(r)
>>> e.pack()
[I enter some text]
>>> a=e.get()
>>> a+=" ...continue"
>>> e.delete(0,END)
>>> e.insert(END,a)

The best documentation for Tkinter that I know of is Fredrik Lundh's
excellent An Introduction to Tkinter. It's at:

http://www.pythonware.com/library/tkinter/introduction/index.htm

I almost always have a local copy open when I'm doing Tkinter
programming.

Regards,
Matt



More information about the Python-list mailing list