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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

retrieve the number of the last line of a text widget

Status
Not open for further replies.

papageno

Technical User
Dec 25, 2004
24
0
0
ES
I need to use that number in an expression like:

if {the number of the last line is a multiple of X} {
do something
}
 
Let's say your text widget is .frame1.text1.
The statement: .frame1.text1 index end will return the location of the last insertion (including a linefeed if that were the last "character") in the form, line.char. Split the returned string on "." and the 0th element is the line number.

Bob Rashkin
rrashkin@csc.com
 
Great, thank you.

So this works:

Code:
.text -width n -height n -font {name n}
pack .text

set astring "my string"
set lastline [lindex [split [.text index end] .] 0]
if {[expr $lastline % 26] == 0} {
   .text insert end $astring
}

Now I would like the string to start with a tab, but

.text -width n -height n -font {name n} -tab n
etc...
set astring "\tmy string"
etc...

displays "\t" as the default 8 character tab. Am I missing something?
 
I don't know of a "-tab" option in the text widget. There is a "-tabs" option but the syntax there is for a number of centimeters or inches. Assuming you meant -tabs $n, and the units default, I don't know why it isn't working. Try instantiating the text widget without specifying the tab spacing. If that doesn't work try this:
set astring \t
append astring "my string"

I don't know what it means if it works or even if it doesn't.

Bob Rashkin
rrashkin@csc.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top