[Tkinter-discuss] how to get all the text from a text widget?

Guilherme Polo ggpolo at gmail.com
Thu May 15 01:41:42 CEST 2008


Snakey <darr_low <at> yahoo.com> writes:

> 
> 
> I created a text widget to allow my users to enter some lines of text.  Now I
> need to dump all the text contents into a string variable.  How can i do
> that?

Supposing you have no tags, you could do:

text.get('1.0', 'end') # text is your text widget

The first parameter is the index1 specifying where to start looking for text,
and the other parameter is the index2, where to stop looking for text (one
before it). Lines are numbered from 1 and columns from 0, that is why I used
'1.0' (which is accepted as an index), and 'end' is an special index which
indicates the end of the text.




More information about the Tkinter-discuss mailing list