![]() ![]() ('', self.show_image) # canvas is resized nfigure(command=self.scroll_y) # bind scrollbars to the canvas Self.canvas = tk.Canvas(self.master, highlightthickness=0, Hbar = AutoScrollbar(self.master, orient='horizontal') Vbar = AutoScrollbar(self.master, orient='vertical') # Vertical and horizontal scrollbars for canvas Raise tk.TclError('Cannot use place with this widget') Raise tk.TclError('Cannot use pack with this widget') Works only if you use the grid geometry manager ''' ''' A scrollbar that hides itself if it's not needed. # constant memory and not crams it with a huge resized image for the large zooms. # It zooms only a tile, but not the whole image. Tested on Windows 7 64-bit and Python 3.6.2.ĭo not forget to place a path to your image at the end of the script. For the simplified zoom example look here. So the zoomed tile occupies constant memory and not crams it with a huge resized image for the large zooms. It zooms only a tile, but not the whole image. How to have a move/pan + zoom feature on Tkinter canvas, that works for images?Īdvanced zoom example. We could think about rendering the viewport only, or a bit more than the current viewport to allow panning, but then what to do once panning leads to the edge of the rendered zone? How to avoid having a 50.000 x 50.000 pixels bitmap in memory? (2.5 gigapixels in RAM is too big). Let's say we have 1000x1000 bitmap on the canvas, and we want to zoom by a factor 50x. We absolutely need to render more than the currently displayed area, to allow move/pan. But:Īs we are redrawing a particular portion of the canvas, move/pan feature won't work anymore. Zoom the vector elements on the canvas with canvas.scale, but sadly, this doesn't work for bitmap images on the canvasįortunately, this method allows zooming of images (by manually redrawing the zoomed portion of the image). ![]() Move/pan the canvas (for example with Click + Drag) with canvas.scan_mark and canvas.scan_dragto, see this question Tkinter's canvas widget has built-in features to:
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |