How to save text in a text widget? 
Author Message
 How to save text in a text widget?

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
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!

Josh {*filter*}

P.S. Thanks to everyone who has helped me already!



Mon, 15 Nov 1999 03:00:00 GMT  
 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

                        .
                        .
                        .
Both, as <URL:http://www.elf.org/tcltk-man-html/TkCmd/entry.htm>
documents.  If

                # You can choose your own names for ENTRY_WIDGET
                #     and YOUR_VARIABLE.
        entry $ENTRY_WIDGET -textvariable YOUR_VARIABLE

then later

        global YOUR_VARIABLE
        puts -nonewline "Here are two ways to show the same value:"
        puts "  $YOUR_VARIABLE; [$ENTRY_WIDGET get]."
--

Cameron Laird           http://starbase.neosoft.com/~claird/home.html

                        +1 713 996 8546 FAX



Mon, 15 Nov 1999 03:00:00 GMT  
 How to save text in a text widget?

Quote:

> I want to save the text i write into a text widget, does it have a
> textvariable or somthing that i can use?

Entry widgets have text variables, but the text widget can do too much to
just be equivalent to a variable. What you probably are looking for is the
"get" subcommand, as in

  set textVar [.your.widget get 1.0 end]

Now we're at it, is there an inverted "dump" subcommand, or something related,
that can be used to completely restore the previously saved contents of a
text widget, *including* tag positions and configurations? Would be nice to
have; I now spend a lot of programming time converting internal tags to
some external representation that can be dropped into a file.

--
Jeroen Hoppenbrouwers, Senior Researcher at     |  Stop connecting computers;
Infolab, Tilburg University, The Netherlands    |  start connecting people!
             http://infolabwww.kub.nl:2080/infolab/people/hoppie



Tue, 16 Nov 1999 03:00:00 GMT  
 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



Tue, 16 Nov 1999 03:00:00 GMT  
 How to save text in a text widget?

Quote:


>> I want to save the text i write into a text widget, does it have a
>  set textVar [.text get 1.0 end]

It should be noted that this should be:
        set textVar [.text get 1.0 end-1c]
if you really want to get the true inserted contents of the text widget.
The text widget maintains an extra end of text newline that you want to
avoid if the true inserted contents of te text are important (which should
be 98% of the time).

Quote:
>Now we're at it, is there an inverted "dump" subcommand, or something related,

Since there are several options to [.text dump ...] it is up to the
programmer to write such a procedure, although a default one would make
a good FAQ answer...

--

  Software Engineer, Oregon R&D        office: 541.683.7891
  CADIX International, Inc.            fax:    541.683.8325
             URL: http://www.cs.uoregon.edu/~jhobbs/



Tue, 16 Nov 1999 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Some questions on elided text in the text widget (and a few other text widget questions)

2. embedding text widgets in other text widgets

3. Newbie - Saving text from text window

4. How to save new text in text box

5. Save text from Tk widget?

6. Tkinter, Saving chages to text in ScrolledText Widget

7. determine whether text widget content changed since last save

8. Saving the contents of a text widget

9. saving text widget changes

10. Newbie: Text Widget Save Problem-Help

11. Saving a text widget to a file

12. How to use text widget to save

 

 
Powered by phpBB® Forum Software