2021-12-28 13:31:58 +00:00
|
|
|
import tkinter as tk
|
|
|
|
import tkinter.ttk as ttk
|
|
|
|
|
|
|
|
class Controller(object):
|
|
|
|
def __init__(self, app):
|
|
|
|
self.app = app
|
|
|
|
|
|
|
|
self.selected = None
|
|
|
|
self.selected_start = None
|
|
|
|
self.selected_end = None
|
|
|
|
|
|
|
|
def run_process(self):
|
|
|
|
print("Run")
|
|
|
|
self.app.main_canvas.bind('<1>', self.make_circle)
|
|
|
|
self.app.main_canvas.bind('<3>', self.select_item)
|
2022-04-19 20:40:06 +00:00
|
|
|
self.app.main_canvas.bind('<Shift-1>', self.select_for_line)
|
2021-12-28 13:31:58 +00:00
|
|
|
return 0
|
|
|
|
|
|
|
|
def make_circle(self, event):
|
|
|
|
x = event.x
|
|
|
|
y = event.y
|
|
|
|
r = 20
|
|
|
|
self.app.main_canvas.create_oval(x-r, y-r, x+r, y+r, fill="white", outline="black", tag="circle")
|
|
|
|
|
|
|
|
def select_item(self, event):
|
|
|
|
self.app.main_canvas.bind('<Motion>', self.move_item)
|
|
|
|
self.app.main_canvas.bind('<1>', self.deselect_item)
|
|
|
|
self.app.main_canvas.addtag_withtag('selected', tk.CURRENT)
|
|
|
|
|
|
|
|
def deselect_item(self, event):
|
|
|
|
self.app.main_canvas.dtag('selected')
|
|
|
|
self.app.main_canvas.unbind('<Motion>')
|
|
|
|
self.app.main_canvas.bind('<1>', self.make_circle)
|
|
|
|
|
|
|
|
def move_item(self, event):
|
|
|
|
x = event.x
|
|
|
|
y = event.y
|
|
|
|
r = 20
|
|
|
|
self.app.main_canvas.coords("selected",x-r, y-r, x+r, y+r)
|
|
|
|
|
|
|
|
def select_for_line(self, event):
|
2022-04-19 20:40:06 +00:00
|
|
|
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)
|
2021-12-28 13:31:58 +00:00
|
|
|
|
2022-04-19 20:40:06 +00:00
|
|
|
def move_line(self, event):
|
|
|
|
x = event.x
|
|
|
|
y = event.y
|
|
|
|
self.app.main_canvas.coords("newline",self.x0,self.y0,x,y)
|
2021-12-28 13:31:58 +00:00
|
|
|
|
|
|
|
class Application(tk.Tk):
|
|
|
|
def __init__(self):
|
|
|
|
super().__init__()
|
|
|
|
self.con = Controller(self)
|
|
|
|
self.create_control_variables()
|
|
|
|
self.create_widgets()
|
|
|
|
|
|
|
|
def create_control_variables(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def create_widgets(self):
|
|
|
|
self.main_canvas = tk.Canvas(master=self, width=500, height=400, background='gray75')
|
|
|
|
self.main_canvas.grid(row=0, column=0)
|
|
|
|
|
|
|
|
self.b = ttk.Button(master=self, text="Start", command=self.con.run_process)
|
|
|
|
self.b.grid(row=1, column=0)
|
|
|
|
|
|
|
|
|
|
|
|
# --------------------------
|
|
|
|
# Execution
|
|
|
|
# --------------------------
|
|
|
|
if __name__ == "__main__":
|
|
|
|
app = Application()
|
|
|
|
app.mainloop()
|