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!

Anchor in canvas

Status
Not open for further replies.

Anto35

Technical User
May 16, 2002
25
0
0
FR
I want to know how does the anchor works when we insert a bitmap file in a canvas.
I try to fill the canvas with a bitmap of the same size but I don't understand how does the anchor works in the canvas and the bitmap isn't well placed!

- Example:
# Create and place canvas
canvas .cnvs -borderwidth 0 -height 96 -width 216
place .cnvs -x 125 -y 10 -anchor nw
# Insert a new bitmap
set filename "$::env(HOME)/screen.bmp"
.cnvs create bitmap X Y -bitmap @$filename -tags scr

Now if I affect 0 into X and Y, I see only a part of my bitmap, I have to set X to 109 and Y to 50 to see the entire bitmap on the canvas.

PS: I don't want to use something like:
"canvas .cnvs -bitmap @$filename..." because the content of the canvas often change.

Thanx for your answers, Anto.
 
I assume that you've got good reasons for using place to manage your canvas, rather than using pack or grid. Personally, I think I've resorted to using place for geometry management maybe once in all the Tcl scripts I've written. pack and grid are much more powerful, and if you're not familiar with them, I highly recommend that you read up on them; grid is especially easy to learn, as it's similar to placing widgets into cells of a spreadsheet. But on to your main question...

The -anchor option determines where the bitmap is positioned relative to the coordinates you specify. The default anchoring is centered (-anchor c), which means that the bitmap would be centered over the X/Y coordinates. Given the code you've included above, I suspect that you'd like to anchor your bitmap nw, so that the northwest (that is, upper-left) corner of the bitmap is at 0,0:

[tt].cnvs create bitmap 0 0 -anchor nw -bitmap @$filename -tags scr[/t] - 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