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

textwidget scrollbar and output file

Status
Not open for further replies.

magicme

Technical User
Jun 11, 2003
22
US
hello again

i still have the font problem i posted yesterday .... this is a new topic.

i have a vertical scrollbar attached to a text widget and it works just fine. but if i scroll down (move text up) and then write the contents of the text widget to a file, the output does not start at the *actual* first line of the text widget....it starts at the *visible* first line .... that is, the scrollbar seems to have moved the start index to the first visible position in the window. i have tried a number of things to write out the entire contents of the text widget .....here is one where i tried using a mark at the start of the *actual* text.... (this scheme also opens a file dialog box to select the output file ....which works fine )
# define the write button
button .textframe.writebutton \
-background $buttoncolor \
-foreground $buttforecolor \
-font davesfont \
-padx $padding -pady $padding\
-width $buttonwidth \
-height $buttonheight \
-text "write" \
-command {
# set a mark at the very beginning of the textbox.....
.textframe.maintextbox mark set beginmark 1.0;
set initialdir [pwd];
set file_types { \
{ "Tcl Files" { .tcl .TCL .tk .TK } } \
{ "Text Files" { .txt .TXT .dat .DAT } } \
{ "HTML Files" { .html .HTML .htm .HTM } } \
};
# open file dialog box
set outputfile [tk_getSaveFile \
-initialdir $initialdir \
-filetypes $file_types \
-parent .textframe.maintextbox]
# write out text to file
set junkfilename [open $outputfile w+];
puts $junkfilename [.textframe.maintextbox get beginmark end];
close $junkfilename
}
# .........................................

my question is: when using a vertical scrollbar, how can i set the starting point for output back to the first character of the actual text in the box (without having to remember to scroll all the way back to the top).

thanks for your time.

daveleo
 
I think you're doing it right but sometimes I've found that an "inline" command has scope problems (yes, I know you have absolute references so it shouldn't be that). Just for grins, try putting your write routine in a proc and having the -command reference that proc.

_________________
Bob Rashkin
 
thanks Bong.

for the record, here is what worked....

#
#
proc writethefile {} {
# set a mark at the very beginning of the textbox.....
.textframe.maintextbox mark set beginmark 1.0;
# make \outputfile\ a global variable (for other reasons)
global outputfile
set initialdir [pwd];
set file_types { \
{ "HTML Files" { .html .HTML .htm .HTM } } \
{ "Text Files" { .txt .TXT .dat .DAT } } \
{ "Tcl Files" { .tcl .TCL .tk .TK } } \
};
set outputfile [tk_getSaveFile \
-initialdir $initialdir \
-filetypes $file_types \
-parent .textframe.maintextbox];
set junkfilename [open $outputfile w+];
puts $junkfilename [.textframe.maintextbox get beginmark end];
close $junkfilename
}
#
#
# buton to write to call the procedure ....
button .textframe.writebutton \
-background $buttoncolor \
-foreground $buttforecolor \
-font davesfont \
-padx $padding -pady $padding\
-width $buttonwidth \
-height $buttonheight \
-text "write" \
-command {writethefile}
#
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top