Tkinter.Text.index() puzzlement
Matthew Dixon Cowles
matt at mondoinfo.com
Sat Apr 20 22:50:22 EDT 2002
On Sun, 21 Apr 2002 00:59:04 GMT, David R. Smith
<DSmithSprint05 at earthlink.net> wrote:
Dear David,
>Matthew, thanks for your response.
You're very welcome.
>I'm trying to add a textual read-eval-print cycle onto a program
>which is mainly GUI-driven. I thought I'd set a marker at the end of
>the computer-generated output, e.g.,
> marker = text.index(END)
>and then when the <Return> event strikes, pick up the text between
>marker and text.index(END) as of that time, and send it off to eval.
>This keeps resulting in null strings, even though I entered
>"123+456<Return>". Then the string might belatedly come through. Is
>it hopeless to use text.index() to do useful work?
I suspect that that depends on your definition of hopeless <wink>. As
part of a larger project, I've been working on an undo function for
the Text widget for some time and I still haven't gotten it to figure
out just how the thing behaves in all situations.
On the other hand, it seems that what you're describing ought to be
possible:
>>> from Tkinter import *
>>> r=Tk()
>>> t=Text(r)
>>> t.pack()
>>> t.insert(END,"Wibble")
>>> i=t.index(END) # Entered some text after this line
>>> t.get(i,END)
'Text Text Text\n\n'
You might also want to have a look at the code for IDLE. It seems to
do something like what you're describing.
Regards,
Matt
More information about the Python-list
mailing list