-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
63 lines (44 loc) · 1.28 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from tkinter import Tk, BOTH, Canvas
class Window():
def __init__(self, width, height):
self.width = width
self.height = height
self.__root = Tk()
self.__root.title("Title")
self.canvas = Canvas(self.__root, width=self.width, height=self.height)
self.canvas.pack()
self.running = False
self.__root.protocol("WM_DELETE_WINDOW", self.close)
def redraw(self):
self.__root.update_idletasks()
self.__root.update()
def wait_for_close(self):
self.running = True
while self.running:
self.redraw()
def close(self):
self.running = False
def draw_line(self, Line, fill_color):
Line.draw(self.canvas, fill_color)
class Point():
def __init__(self, x, y):
self.x = x
self.y = y
class Line():
def __init__(self, pt1, pt2):
self.x1 = pt1.x
self.x2 = pt2.x
self.y1 = pt1.y
self.y2 = pt2.y
def draw(self, canvas, fill_color):
canvas.create_line(
self.x1, self.y1, self.x2, self.y2, fill=fill_color, width=2
)
def main():
win = Window(800, 600)
pt1 = Point(0, 0)
pt2 = Point(500, 500)
l1 = Line(pt1, pt2)
win.draw_line(l1, "red")
win.wait_for_close()
main()