Hi, I am new to TCL. What I want to do is to get the contents of a text file, split it in pages and then display one page at a time on a text widget (with no scrollbar, just by clicking on a button).
When you define the text widget, you can specify how may lines to make it show: text .<path>.<widgetname> -height <number of lines>
Then, what I would do is read in the whole file and split it into a list of lines: set fid [open <filename> r]
set linelist [split [read $fid] \n]
close $fid
Now figure out how many pages you have: set numlines [llength $linelist]
set numpages [expr {ceil($numlines/<number of lines>)}]
now loop through the number of pages when the button is pushed: button .<path>.<button name> -text page -command {set pno [nxtpg pno]}
set pno 0
proc nxtpg {pno} {
global linelist <number of lines> numpages
if {$pno >= $numpages} {return $pno}
set ix1 [expr {1+$<number of lines>*$pno}]
set ix2 [expr {$ix1+$<number of lines>}]
for {set i $ix1} {$i<$ix2} {incr i} {
.<path>.<textwidgetname> insert end [lindex $linelist $i]\n
}
incr pno
return $pno
}
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.