import tkinter as tk

class DrawApp:
    def __init__(self):
        self.current_stroke: Stroke = []

        self.root = tk.Tk()
        self.root.title("Dessin !")
        self.canvas = tk.Canvas(self.root,
                                width=800,
                                height=600,
                                bg="white",
                                highlightthickness=0)
        
        self.canvas.pack(fill="both", expand=True)
        self.canvas.bind("<ButtonPress-1>", self._on_button_press)
        self.canvas.bind("<B1-Motion>", self._on_mouse_move)
        self.canvas.bind("<ButtonRelease-1>", self._on_button_release)
        self.root.mainloop()
        
    def _on_button_press(self, event):
        self.clear()        
        self.current_stroke = [(event.x, event.y)]

    def _on_mouse_move(self, event):
        new_point = (event.x, event.y)
        self.current_stroke.append(new_point)

        self.canvas.create_line(self.current_stroke[-2][0],
                                self.current_stroke[-2][1],
                                new_point[0],
                                new_point[1],
                                width=2,
                                fill="black",
                                capstyle=tk.ROUND,
                                smooth=True)

    def _on_button_release(self, event):
        self.current_stroke.append((event.x, event.y))
        print(self.current_stroke)
        
    def clear(self):
        self.canvas.delete("all")

if __name__ == "__main__":
    app = DrawApp()
