-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwindow.py
58 lines (42 loc) · 1.51 KB
/
window.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
from tkinter import Tk, BOTH, Canvas
from line import Line
from utils import BACKGROUND_COLOR, LINE_COLOR
class Window:
"""
width and height are the size of the new window in pixels.
title is the self.__root title.
"""
def __init__(self, width: int, height: int, title: str) -> None:
self.__root = Tk()
self.__root.title(title)
self.__root.protocol("WM_DELETE_WINDOW", self.close)
self.__canvas = Canvas(self.__root, bg=BACKGROUND_COLOR, width=width, height=height)
self.__canvas.pack()
self.__is_window_running = False
def redraw(self) -> None:
"""
call self.__root.update_idletasks() and self.__root.update()
to redraw the screen.
"""
self.__root.update_idletasks()
self.__root.update()
def wait_for_close(self) -> None:
"""
set self.__is_window_running to True
call self.redraw() until self.__is_window_running is False
"""
self.__is_window_running = True
while self.__is_window_running is True:
self.redraw()
def close(self) -> None:
"""
set self.__is_window_running to False
"""
self.__is_window_running = False
def draw_line(self, line: Line, fill_color: str = LINE_COLOR) -> None:
"""
Draw a line between two Point's in a Canvas.
line: Line class
fill_color: TK Color (name of the color or HEX #rrggbb value)
"""
line.draw(self.__canvas, fill_color)