[Tutor] Re; Making a text box read-only.

Jose Amoreira amoreira@mercury.ubi.pt
Mon, 05 Mar 2001 16:35:45 +0000


Hi.

You can get the contents of a text widget using the
Text.get(start_index,end_index) method. The first char in the text widget
has
an index line.col='1.0'; the last one's index is END.

Here follows a sample interpreter session:
pandora:exam$ python
Python 2.0 (#5, Jan 22 2001, 11:06:56)
[GCC egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)] on linux2
Type "copyright", "credits" or "license" for more information.
>>> from Tkinter import *
>>> r=Tk()
>>> t=Text(r)
>>> t.pack()
>>> #type some garbage in the text widget...
...
>>> t.get('1.0',END)
"hello, how are you?\012I'm fine thank you.\012\012"
>>> print t.get('1.0',END)
hello, how are you?
I'm fine thank you.

>>> ^D
I think that it is also possible to use Tkinter's StringVar class to get the
contents of a text (or entry) widget (and to update it automatically), but I
really don't know exactly how it's done.

Cheers,
Ze Amoreira
amoreira@mercury.ubi.pt


Chris McCormick wrote:

> [...]
>  While we're at it, I'm stuck with my own text box
> problem.  I know this has ot be simple, but I can't
> find it in any of the Tkinter docs I have.  **How do I
> grab the contents of the box?**
>
> I'm writing a notes program.  I want to have a button
> that will set off a function to grab the text in the
> box and input it into a text file.  What is the name
> of the data structure that contains the information
> typed into the box?  It's probably a list full of
> individual lines....
>
> Hope that helps, and maybe someone will answer my
> piggyback question.  :-)
>
> - Chris