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!

Visibility of Entire Region in the Canvas

Status
Not open for further replies.

SmallProgram

Programmer
Feb 6, 2002
42
IN
Hello Friends,
I have some serious Problem.
Iam sending the code.
please check the code and suggest me the solution for this Problem.
Ihave acanvas where Iam setting the scrollregion as given in the canvas.
In the canvas The mouse Event of B1 and Buttonrelease are bound.
We can draw a line with the help of these bindings. The problem is that Once I scroll down the canvas and want to draw the line there Iam not able to get the line at the position I wanted the line to be.
Can u sugget me any answer how to get the line at the place Iam pressing the Button and leaving the Mouse Button.
Thanks In Advance .
Please set the Tab settings In your Machine.
The code reads as

wm withdraw .
toplevel .dialog

canvas .dialog.c -height 900c -width 800c -yscrollcommand {.dialog.sb set} -background white -scrollregion {0c 0c 100c 100c}
scrollbar .dialog.sb -orient vertical -command {.dialog.c yview}

button .dialog.close -text "Close window" -command {wm withdraw .dialog
}

grid .dialog.c -row 0 -column 0 -sticky nsew -pady 4 -padx 2
grid .dialog.sb -row 0 -column 1 -sticky ns -pady 4 -padx 2
grid .dialog.close -row 1 -column 0 -columnspan 2 -pady 2
grid columnconfigure .dialog 0 -weight 1
grid rowconfigure .dialog 0 -weight 1

global X1 Y1
bind .dialog.c <Button-1> {set X1 %x;set Y1 %y;}
bind .dialog.c <ButtonRelease-1> {
.dialog.c create line $X1 $Y1 %x %y -fill red
}
Programmer,Amatuer
 
I tried your code that ran perfectly.
I only modified the screen units to have more manageable dimensions:
Code:
canvas .dialog.c -height 900 -width 800 -yscrollcommand {.dialog.sb set}                  -background white -scrollregion {0 0 100 100}
Removing the c after the numbers, I get the dimensions in pixels.

Maybe a scrollregion of 100 x 100 cm (1 x 1 m) make some troubles?

ulis

 
A common problem when people start scrolling canvas widgets. Read my reply to the message &quot;Canvas coordinate system,&quot; thread287-212500, for a discussion of what's going on and how to fix it. For the specific exmple you provided, you'll need to change the following lines:

[tt]bind .dialog.c <Button-1> {
set X1 [ignore][canvasx[/ignore] %x[ignore]][/ignore]
set Y1 [ignore][canvasy[/ignore] %y[ignore]][/ignore]
}
bind .dialog.c <ButtonRelease-1> {
.dialog.c create line $X1 $Y1 [ignore][canvasx[/ignore] %x[ignore]][/ignore] [ignore][canvasy[/ignore] %y[ignore]][/ignore] -fill red
}[/tt] - Ken Jones, President
Avia Training and Consulting
866-TCL-HELP (866-825-4357) US Toll free
415-643-8692 Voice
415-643-8697 Fax
 
With an other effort I found another problem between the window dimensions and the scrollregion.
The height and width are the window dimensions.
The scrollregion is the drawing region (more larger).
Here is a new code where I changed the dimensions, added a horizontal scrollbar and added %W before canvasx and canvasy.
Code:
wm withdraw .
toplevel .dialog

canvas .dialog.c -height 400 -width 400                  -yscrollcommand {.dialog.vsb set}                  -xscrollcommand {.dialog.hsb set}                  -background white                  -scrollregion {0 0 800 800}
scrollbar .dialog.vsb -orient vertical           -command {.dialog.c yview}
scrollbar .dialog.hsb -orient horizontal           -command {.dialog.c xview}

button .dialog.close -text &quot;Close window&quot;           -command {wm withdraw .dialog}

grid .dialog.c -row 0 -column 0 -sticky nsew -pady 4 -padx 2
grid .dialog.vsb -row 0 -column 1 -sticky ns -pady 4 -padx 2
grid .dialog.hsb -row 1 -column 0 -sticky ew 
grid .dialog.close -row 2 -column 0 -columnspan 2 -pady 2
grid columnconfigure .dialog 0 -weight 1
grid rowconfigure .dialog 0 -weight 1

global X1 Y1
bind .dialog.c <Button-1> {set X1 [%W canvasx %x];set Y1 [%W canvasy %y];}
bind .dialog.c <ButtonRelease-1> { .dialog.c create line $X1 $Y1 [%W canvasx %x] [%W canvasy %y] -fill red }

ulis
 
Thank U Mr.Ken and Mr.Ulis.
I have got the solution.
Mallik Programmer,Amatuer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top