Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from pprint import pprint
- from tkinter import *
- root = Tk()
- root.geometry("600x400")
- root.title("Рисовалка")
- root['bg'] = "gray75"
- root.resizable(False, False)
- cv = Canvas(root, width=540, height=400, bg="white")
- cv.grid(row=0, column=0, rowspan=7)
- state = "circle"
- brush = 10
- color = "red"
- def choose(button_name):
- global state
- state = button_name
- def paint(event):
- if event.widget.__class__ is not Canvas:
- print("Ты нажал не на Холст!")
- return
- if state == "circle":
- cv.create_oval(event.x - brush, # Координата x1
- event.y - brush, # Координата y1
- event.x + brush, # Координата x2
- event.y + brush, # Координата y2
- fill=color, # Цвет заливки
- outline=color) # Цвет обводки
- elif state == "square":
- cv.create_rectangle(event.x - brush, event.y - brush,
- event.x + brush, event.y + brush,
- fill=color, outline=color)
- elif state == "line1":
- cv.create_line(event.x - brush, event.y - brush,
- event.x + brush, event.y + brush, fill=color)
- elif state == "line2":
- cv.create_line(event.x + brush, event.y - brush,
- event.x - brush, event.y + brush, fill=color)
- pprint(event.__dict__)
- root.bind_all("<1>", paint)
- root.bind_all("<B1-Motion>", paint)
- square_btn = Button(root, text="🟥", font=(None, 20), command=lambda: choose("square"))
- square_btn.grid(row=0, column=1)
- circle_btn = Button(root, text="🔴", font=(None, 20), command=lambda: choose("circle"))
- circle_btn.grid(row=1, column=1)
- line1_btn = Button(root, text=" ↘ ", font=(None, 20), command=lambda: choose("line1"))
- line1_btn.grid(row=2, column=1)
- line2_btn = Button(root, text=" ↙ ", font=(None, 20), command=lambda: choose("line2"))
- line2_btn.grid(row=3, column=1)
- plus_btn = Button(root, text="➕", font=(None, 20), command=lambda: choose("plus"))
- plus_btn.grid(row=4, column=1)
- minus_btn = Button(root, text="➖", font=(None, 20), command=lambda: choose("minus"))
- minus_btn.grid(row=5, column=1)
- size = Label(root, text=brush, fg=color, font=(None, 32))
- size.grid(row=6, column=1)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement