-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path5. Paint
More file actions
76 lines (63 loc) · 2.08 KB
/
Copy path5. Paint
File metadata and controls
76 lines (63 loc) · 2.08 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
from tkinter import *
canvas_width = 700
canvas_height = 500
brush_size = 3
color = "black"
def paint(event):
global blush_size
global color
x1 = event.x - brush_size
x2 = event.x + brush_size
y1 = event.y - brush_size
y2 = event.y + brush_size
w.create_oval(x1, y1, x2, y2,
fill=color, outline=color)
def brush_size_change(new_size):
global brush_size
brush_size = new_size
def color_change (new_color):
global color
color = new_color
root = Tk()
root.title("Paint on Python")
w = Canvas(root,
width=canvas_width,
height=canvas_height,
bg="white")
w.bind("<B1-Motion>", paint)
red_btn = Button(text="Red", width=10,
command=lambda: color_change("red"))
blue_btn = Button(text="Blue", width=10,
command=lambda: color_change("blue"))
black_btn = Button(text="Black", width=10,
command=lambda: color_change("black"))
white_btn = Button(text="Eraser", width=10,
command=lambda: color_change("white"))
clear_btn = Button(text="Delete all", width=10,
command=lambda: w.delete("all"))
one_btn = Button(text="2", width=10,
command=lambda: brush_size_change(2))
five_btn = Button(text="5", width=10,
command=lambda: brush_size_change(5))
ten_btn = Button(text="10", width=10,
command=lambda: brush_size_change(10))
twelve_btn = Button(text="12", width=10,
command=lambda: brush_size_change(12))
twenty_btn = Button(text="20", width=10,
command=lambda: brush_size_change(20))
w.grid(row=2, column=0,
columnspan=7, padx=5,
pady=5, sticky=E+W+S+N)
w.columnconfigure(6, weight=1)
w.rowconfigure(2, weight=1)
red_btn.grid(row=0, column=2)
blue_btn.grid(row=0, column=3)
black_btn.grid(row=0, column=4)
white_btn.grid(row=0, column=5)
clear_btn.grid(row=0, column=6, sticky=W)
one_btn.grid(row=1, column=2)
five_btn.grid(row=1, column=3)
ten_btn.grid(row=1, column=4)
twelve_btn.grid(row=1, column=5)
twenty_btn.grid(row=1, column=3)
root.mainloop()