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

storing contents of a Tk widget

Status
Not open for further replies.

shussai2

Programmer
Aug 28, 2003
42
0
0
CA
Hi,

Simple question. I have a frame and a canvas and I want to store the contents of these in a variable. Can any please help me with that? Here is my code:

canvas .frame1.canvas1
pack .frame1.canvas1
.frame1.canvas1 create rectangle 50 50 250 250 -fill red

set c $.frame1.canvas1
line above this does not places the contents of the canvas in c, therefore when I print contents of c as a label, it displays $.frame1.canvas1----------------------------------

frame .frame2
pack .frame2 -padx 10 -pady 10
label .frame2.label1 -text $c
pack .frame2.label1

 
so, what do you actually want to store in variable c ?
the rectangle? (-:


 
Yes I want to store the rectangle in the variable.
 
The name of the rectangle?
If so, Tk returns the name when the rectangle (or any shape) is created.
Change: [red].frame1.canvas1 create rectangle 50 50 250 250 -fill red
[/red]
to: [blue]set <varname> [.frame1.canvas1 create rectangle 50 50 250 250 -fill red] [/blue]

Bob Rashkin
rrashkin@csc.com
 
Hi,

My goal is to save the contents of the canvas in a variable then use Image extension to write the contents stored in that variable as a gif image. Hence to do so this what I am doing now:


package require BLT
package require Img

frame .frame1
pack .frame1 -padx 10 -pady 10

canvas .frame1.canvas1
pack .frame1.canvas1

set filename HelloB

set c [.frame1.canvas1 create rectangle 50 50 250 250 -fill red]

#save canvas as GIF image file (requires Img extension)
image create photo .photo
.photo configure -format window -data $c
.photo write $filename -format gif


You can try running this code by copying and pasting it in a file. It produces an error saying:
couldn't recognize data while executing ".photo ....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top