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

Index increment question 1

Status
Not open for further replies.

fabien

Technical User
Sep 25, 2001
299
AU
HI!

Following onto my previous post RE text hightlight
I know how to get the point of the mouse from a text widget using the proc
proc keep {var x y} { set ::$var [.t index @$x,$y] }

so I can set start and end points. Say that
start =1.2 and end = 1.20

now I want to increment the y value of start or end by 1
to get
newstart = 1.3, 1.4....

how can do this?

Thanks!
 
Code:
  pack [text .t -width 20 -height 10]
  .t tag config highlight -background navy -foreground white
  for {set i 0} {$i < 10} {incr i}   { .t insert end &quot;yet another line ($i)\n&quot; }
  proc highlight {start end}   {
    # get columns
    set cs [lindex [split $start .] end]
    set ce [lindex [split $end .] end]
    # get rows count
    set max [lindex [.t index end] 0]
    # remove old highlight
    .t tag remove highlight 1.0 end
    # loop thru lines
    for {set row 0} {$row < $max} {incr row}     {
      .t tag add highlight $row.$cs $row.$ce
    }
  }
  highlight 2.4 2.15
The trick is to split compound text addresses as
Code:
2.4
with split, take the row or column part with lindex and then recompose a compound adress with
Code:
$row.$col
.

More on split at: More on lindex at:
HTH

ulis
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top