индикатор не отражает реальный размер import tkinter as tk
from tkinter.colorchooser import askcolor

class DrawingApp:
    def __init__(self, root):
        self.root = root
        self.screen_width = round(root.winfo_screenwidth() / 1.5)
        self.screen_height = round(root.winfo_screenheight() / 1.5)
        x_offset = (root.winfo_screenwidth() - self.screen_width) // 2 - 10
        y_offset = (root.winfo_screenheight() - self.screen_height) // 2 - 45
        self.root.geometry(f"{self.screen_width}x{self.screen_height}+{x_offset}+{y_offset}")
        self.root.title("Программа для рисования")

        # Панель инструментов
        self.toolbar = tk.Frame(self.root, bg="lightgray")
        self.toolbar.pack(side=tk.TOP, fill=tk.X)

        # Холст для рисования
        self.canvas = tk.Canvas(self.root, bg="white", width=1920, height=900)
        self.canvas.pack(fill=tk.BOTH, expand=True)
        
        # Инициализация переменных
        self.drawing = False
        self.last_x = None
        self.last_y = None
        self.color = "black"
        self.tool = "brush"  # кисть по умолчанию
        self.size = 5  # Размер кисти/ластика
        self.indicator = None  # Индикатор текущего инструмента
        
        # Кнопки для инструментов
        self.create_button(self.toolbar, "Кисть", self.set_brush)
        self.create_button(self.toolbar, "Ластик", self.set_eraser)
        self.create_button(self.toolbar, "Очистить", self.clear_canvas)
        self.create_button(self.toolbar, "Цвет", self.choose_color)
        self.create_button(self.toolbar, "Круг", self.draw_circle)
        self.create_button(self.toolbar, "Квадрат", self.draw_square)
        
        # Ползунок для изменения размера
        self.size_slider = tk.Scale(self.toolbar, from_=1, to=50, orient=tk.HORIZONTAL, label="Размер", command=self.update_size)
        self.size_slider.set(self.size)  # Устанавливаем начальный размер
        self.size_slider.pack(side=tk.LEFT, padx=5, pady=5)

        # Обработчики событий на холсте
        self.canvas.bind("<Button-1>", self.on_button_press)
        self.canvas.bind("<B1-Motion>", self.on_mouse_drag)
        self.canvas.bind("<ButtonRelease-1>", self.on_button_release)
        self.canvas.bind("<Motion>", self.on_mouse_move)
    
    def create_button(self, parent, text, command):
        button = tk.Button(parent, text=text, command=command)
        button.pack(side=tk.LEFT, padx=5, pady=5)
    
    def set_brush(self):
        self.tool = "brush"
        self.update_indicator()
    
    def set_eraser(self):
        self.tool = "eraser"
        self.update_indicator()
    
    def clear_canvas(self):
        self.canvas.delete("all")
    
    def choose_color(self):
        color = askcolor()[1]
        if color:
            self.color = color
    
    def draw_circle(self):
        self.tool = "circle"
        self.update_indicator()
    
    def draw_square(self):
        self.tool = "square"
        self.update_indicator()
    
    def update_size(self, val):
        """Обновить размер кисти/ластика и индикатор."""
        self.size = int(val)
        self.update_indicator()
    
    def update_indicator(self):
        """Обновить индикатор текущего инструмента."""
        if self.indicator:
            self.canvas.delete(self.indicator)
        
        if self.tool in ["brush", "eraser"]:
            self.indicator = self.canvas.create_oval(self.last_x - self.size, self.last_y - self.size,
                                                     self.last_x + self.size, self.last_y + self.size,
                                                     outline="black", width=2)
        elif self.tool == "circle":
            self.indicator = self.canvas.create_oval(self.last_x - self.size, self.last_y - self.size,
                                                     self.last_x + self.size, self.last_y + self.size,
                                                     outline=self.color, width=2)
        elif self.tool == "square":
            self.indicator = self.canvas.create_rectangle(self.last_x - self.size, self.last_y - self.size,
                                                          self.last_x + self.size, self.last_y + self.size,
                                                          outline=self.color, width=2)
    
    def on_button_press(self, event):
        self.drawing = True
        self.last_x = event.x
        self.last_y = event.y
        self.update_indicator()
    
    def on_mouse_drag(self, event):
        if self.drawing:
            if self.tool == "brush":
                self.canvas.create_line(self.last_x, self.last_y, event.x, event.y,
                                        width=self.size, fill=self.color, capstyle=tk.ROUND, smooth=True)
            elif self.tool == "eraser":
                self.canvas.create_line(self.last_x, self.last_y, event.x, event.y,
                                        width=self.size * 4, fill="white", capstyle=tk.ROUND, smooth=True)
            elif self.tool == "circle":
                self.canvas.create_oval(self.last_x - self.size, self.last_y - self.size,
                                        self.last_x + self.size, self.last_y + self.size,
                                        outline=self.color, width=2)
            elif self.tool == "square":
                self.canvas.create_rectangle(self.last_x - self.size, self.last_y - self.size,
                                             self.last_x + self.size, self.last_y + self.size,
                                             outline=self.color, width=2)
            self.last_x = event.x
            self.last_y = event.y
            self.update_indicator()
    
    def on_button_release(self, event):
        self.drawing = False
        self.last_x = None
        self.last_y = None
    
    def on_mouse_move(self, event):
        """Отображаем индикатор выбранного инструмента рядом с курсором."""
        if self.tool in ["brush", "eraser", "circle", "square"]:
            self.last_x = event.x
            self.last_y = event.y
            self.update_indicator()

if __name__ == "__main__":
    root = tk.Tk()
    app = DrawingApp(root)
    root.mainloop()