Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get all text from Widget

Status
Not open for further replies.

zackiv31

Programmer
May 25, 2006
148
US
I have a Text widget but cannot get the information from it.

I try:

$text -> get (1.0,'end')

and it tells me the index "1" is bad. What is going wrong? Must just be syntax...
 
Well I got it to work somewhat...

When I do the get, tabs are no recognized... is there any way to have an indent be translated into a '\t' ?
 
What language are you working in? "->" isn't Tcl.

_________________
Bob Rashkin
 
OOps... I'm in Perl.. but it's still Tk options am I correct? Only reason why I put it here.
 
All I can tell you is that the Tk syntax you want is:
Code:
<pathname for text widget> get 1.0 end

In your example perhaps $text is the pathname reference? If that's so, and you want to retrieve the contents of the text widget into a string variable, say, stringA, then:
Code:
set stringA [$text get 1.0 end]

_________________
Bob Rashkin
 
Do you guys get tabs recognized from a Tk Text widget? If I capture from the widget, and print it back out.. tabs (not typed \t) are not translated.
 
Not sure what you're asking but I did a little experiment that could answer you anyway.
In a WISH shell, I loaded a text widget:
pack [text .t]

I typed some stuff in the text using tabs:

abc def
fadlj falkm
kladsjkl;lkj lsdaf fasld
adjlk.

Between [red]abc[/red] and [red]def[/red] in the first line is a tab.

I read the contents of the text into a string:
set a [.t get 1.0 end]
I split the string into a list on linefeeds:
set alst [split $a \n]

Now the first element of the string (the first line in the text) is [red]{abc def}[/red]

I find the length of that first element:
string length [lindex $alst 0]
and the answer is [red]7[/red], meaning that the tab is a single character.

_________________
Bob Rashkin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top