69 lines
1.9 KiB
Python
69 lines
1.9 KiB
Python
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)
|
|
self.app.main_canvas.bind('<SHIFT-1>', self.select_for_line)
|
|
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):
|
|
pass
|
|
|
|
|
|
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()
|