Kleine Erweiterung des Canvas-Beispiels

master
Martin Putzlocher 2022-04-19 22:40:06 +02:00
parent ba5b38e7c4
commit b281d61fb5
1 changed files with 13 additions and 2 deletions

View File

@ -13,7 +13,7 @@ class Controller(object):
print("Run")
self.app.main_canvas.bind('<1>', self.make_circle)
self.app.main_canvas.bind('<3>', self.select_item)
self.app.main_canvas.bind('<SHIFT-1>', self.select_for_line)
self.app.main_canvas.bind('<Shift-1>', self.select_for_line)
return 0
def make_circle(self, event):
@ -39,8 +39,19 @@ class Controller(object):
self.app.main_canvas.coords("selected",x-r, y-r, x+r, y+r)
def select_for_line(self, event):
pass
self.app.main_canvas.addtag_withtag("sel_line", tk.CURRENT)
start_coords = self.app.main_canvas.coords("sel_line")
self.x0 = (start_coords[0] + start_coords[2]) // 2
self.y0 = (start_coords[1] + start_coords[3]) // 2
x = event.x
y = event.y
self.app.main_canvas.create_line(self.x0,self.y0,x,y, tag="newline")
self.app.main_canvas.bind('<Motion>', self.move_line)
def move_line(self, event):
x = event.x
y = event.y
self.app.main_canvas.coords("newline",self.x0,self.y0,x,y)
class Application(tk.Tk):
def __init__(self):