
How to save text in a text widget?
Quote:
>Hi, i have another question!
>I want to save the text i write into a text widget, does it have a
>textvariable or somthing that i can use? I need to take the text i save
proc save_text {widget filename {mode w}} {
set f [open $filename $mode]
puts $f [$widget get 0.0 end]
close $f
Quote:
}
Thats all!
use like this:
bind .myframe.mytext <Key-F2> {save_text .myframe.mytext [tk_getSaveFile]}
or
.mymenu.m add command -label "Append existing file" \
-command {save_text .myframe.mytext [tk_getOpenFile] a}
manual pages related to this stuff
1. text(n) - get widget command, INDICES section - how to
get text from text widget, and how to specify
which part of text you want
2. tk_getOpenFile(n) how to request filename for user
3. proc(n) - how to make procedure parameter with default
value (mode parameter in proc above)
Quote:
>and append it to a file, i also need editing of files (ie read them into a
>text widget and modify them, then save them. I know how to do all that
>except i'm having a hard time figuring out how to save text I write in a
>widget! Thanks in advance!
Loading text into widget:
1. Insert content of variable or result of command at
insertion cursor
.widget.pathname insert insert $variable
2. Overwrite all current content of text widget
by content of variable
.widget.pathname delete 0.0 end
.widget.pathname insert 0.0 $variable
3. Appending text by result of command
(redirecting output in text widget
.widget.pathname insert end [command args]
4. Filter selection through Tcl command
set tempvar [.widget.pathname get sel.first sel.last]
.widget.pathname mark set pipe sel.first
.widget.pathname delete sel.first sel.last
.widget.pathname insert pipe [command $tempvar]
I'll highly recommend you print man text out and
learn it by heart. It worth this.
Quote:
>Josh {*filter*}
>P.S. Thanks to everyone who has helped me already!
P.S. I'm writing this letter in my Tcl-written newsreader,
which makes heavy use of features above and more.
Unfortunaltely I forget to embed something like
console window in this newsreader, so I cannot
insert real procedures from this very program into
text it edits. But it is possible with Tcl/Tk.
---------------------------------------------------------------------------
Phone: 7(095)230-80-61 Victor B. Wagner
Fax: 7(095)230-80-42 Dokuchaev Soil Institute, Pyzhevsky lane, 7