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

canvas clearing

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I like to know how to clear a canvas. Supposed I draw something on it and want to clear it before redrawing again. I have a case where I write some text to the canvas. The next time I write some more text to the canvas, the new text overlapped the old text, making it hard to read. What I like to do is to clear the old text and then write the new text.
 
Easy enough. The canvas's delete operation deletes one or more objects. Just specify either the id of an object (the return value when you create the object) or the tag assigned to the object(s).

Here's a little example that you could run interactively (start up an interactive wish interpreter and enter the commands one at a time to see what happens):

Code:
# Create and pack a canvas

pack [canvas .c] -expand yes -fill both

# Create a text object. Save its ID in the
# variable "msg".

set msg [.c create text 10 10 -anchor nw     -text "Hello, World!"]

# Create 2 more text objects and assign
# the tag "status" to each of them. You
# can then manipulate both objects by
# using their tag name instead of their IDs

.c create text 10 30 -anchor nw  -tags status     -text "Here's a line of text"
.c create text 10 50 -anchor nw -tags status     -text "Here's some more text"

# Delete the 2 "status" objects by using
# the tag "status".

.c delete status

# Delete the first object creating by
# specifying its ID.

.c delete $msg

# Create another text object and assign it
# the tag "alert".

.c create text 10 10 -anchor nw  -tags alert     -text "Situation normal"

# Let's replace the text with a new message.
# But instead of deleting the existing object
# and creating a new one, we'll just change
# the configuration of the existing object
# to change the text displayed.

.c itemconfigure alert     -text "It's out of control!"
- Ken Jones, President, ken@avia-training.com
Avia Training and Consulting, 866-TCL-HELP (866-825-4357) US Toll free
415-643-8692 Voice
415-643-8697 Fax
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top