Files
@ eb6c3126cf26
Branch filter:
Location: OneEye/src/gui/resizablecanvas.py - annotation
eb6c3126cf26
920 B
text/x-python
StateBag: optimized estimateDistance, tests for dealing with wrong states
9fa3f70d50ba 9fa3f70d50ba 9fa3f70d50ba 9fa3f70d50ba 9fa3f70d50ba 9fa3f70d50ba 9fa3f70d50ba 9fa3f70d50ba 9fa3f70d50ba 9fa3f70d50ba 9fa3f70d50ba 9fa3f70d50ba 9fa3f70d50ba 9fa3f70d50ba 9fa3f70d50ba 9fa3f70d50ba 9fa3f70d50ba 9fa3f70d50ba 9fa3f70d50ba 9fa3f70d50ba 9fa3f70d50ba 9fa3f70d50ba 9fa3f70d50ba 9fa3f70d50ba 9fa3f70d50ba 9fa3f70d50ba 9fa3f70d50ba 9fa3f70d50ba 9fa3f70d50ba 9fa3f70d50ba 9fa3f70d50ba 9fa3f70d50ba 9fa3f70d50ba 9fa3f70d50ba | import tkinter as tk
class ResizableCanvas(tk.Canvas):
def __init__(self, master=None):
tk.Canvas.__init__(self, master, highlightthickness=0)
self._master=master
self._width=0
self._height=0
master.bind("<Configure>", self._onResize)
def configure(self,*args,**kwargs):
if "width" in kwargs: self._width=kwargs["width"]
if "height" in kwargs: self._height=kwargs["height"]
super().configure(*args,**kwargs)
def _onResize(self, event):
wScale=float(event.width)/self._width
hScale=float(event.height)/self._height
scale=min(wScale,hScale)
self._width*=scale
self._height*=scale
self.scale("all",0,0,scale,scale) # rescale all the objects tagged with the "all" tag
x=(event.width-self._width)/2
y=(event.height-self._height)/2
# place the widget, giving it an explicit size
self.place(in_=self._master, x=x, y=y, width=self._width, height=self._height)
return scale
|