[Tutor] Problem in scalling............

Emil Styrke emil@lysator.liu.se
Wed Apr 30 09:22:38 2003


perl lover <hemanexp@yahoo.com> writes:

> hi,
>    i have a problem in scalling a canvas widget in
> tkinter. I have created a canvas of size 1000 * 1000.
> When i move the mouse over canvas the x,y values of
> mouse pointer are showned in status bar. It is working
> fine with normal canvas(ie, before scalling). I got
> 762*477 as bottom right pixel value.  When i scallled
> the canvas stil i got the same value (762*477) if the
> mouse is placed at bottom right of the canvas. Since i
> used 2 as scalling factor for both x,y, I expect
> bottom right value is as half as normal canvas (ie,
> 381,248). How can i get it? My program is given below.

I'm not an expert at Tkinter, but my impression is that what you get
is the desired behavior. If you want the real x,y coordinates, you
could either manually divide by the scaling factor, or use the
event.x,event.y values instead, possibly subtracting the coordinates
of the top left corner of the canvas widget.

Now that I read a little more careful, I'm not sure I understand what
your problem is, probably due to my lack of knowledge about the canvas
widget.  I'll have to experiment a little with this.

   /Emil

>
>
> from Tkinter import *
>
> class App:
> 	def __init__(self,parent):
> 		self.myparent = parent
> 		self.canvas =
> Canvas(parent,width="1000m",height="1000m")
> 	
> self.canvas.create_rectangle(100,100,200,200,fill='blue')
> self.canvas.bind('<B1-ButtonRelease>',self.ZoomIn)
> 		self.canvas.bind('<Motion>',self.mm)
> 		self.canvas.pack()
>
> 	def ZoomIn(self,event):
> 		self.canvas.scale(ALL,2,2,1.5,1.5)
>
> 	def mm(self,event):
> 		 print
> self.canvas.canvasx(event.x),self.canvas.canvasy(event.y)
>
>
>
> root = Tk()
> myapp =  App(root)
> root.mainloop()
>
> Thanx
>
>
>
> __________________________________
> Do you Yahoo!?
> The New Yahoo! Search - Faster. Easier. Bingo.
> http://search.yahoo.com
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor