Tkinter canvas zooming (sortof)

Bob Greschke bob at passcal.nmt.edu
Fri May 26 13:40:11 EDT 2006


"Bob Greschke" <bob at passcal.nmt.edu> wrote in message 
news:YvSdnfxcW74PsurZnZ2dnUVZ_t6dnZ2d at nmt.edu...
>I have a program that sucks in a list of equipment positions (Lats/Longs), 
>opens a Toplevel frame with a canvas set to, for example, 700x480 pixels, 
>and then does all of the calculations and plots the objects with 10-pixel 
>wide ovals and rectangles.  Now I want to zoom in (or out), but I don't 
>want the ovals and rectangles to change size.  I just want them to spread 
>out or get closer together.  So scale() doesn't seem to be the way to go. 
>What I want to do is just make the "logical" canvas bigger and replot 
>everything, but when I reconfigure the canvas size to make it bigger the 
>Toplevel frame itself gets bigger.  I want the frame to stay the same size, 
>but still be resizable.  I have scrollbars, and they seem to work ok, and 
>scrollregion seems to do what it should, but I can't figure out how to get 
>them to all work together to do what I want.  Help?
>
> Thanks!
>
> Bob

After further fiddling...

I think I kind of figured this out.  I could tell my plotting routine that 
the canvas was twice as large as I originally made it, and it would draw 
everything (i.e. if I drug the frame larger I could see more stuff off the 
edge of the canvas), but the scrollbars would not "activate" so I could 
scroll over to stuff off the edge of the canvas.  What I was doing wrong was 
not setting the scrollregion to the whole new canvas size that I used for 
plotting.  I kept setting it to the size of the visible canvas in the frame 
or not setting it at all.  I almost understand. :)  Now all I have to do is 
be able to grab the canvas and drag it around with the mouse and click on a 
spot and have it center that spot and zoom in there.

Bob





More information about the Python-list mailing list