-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPaint.py
109 lines (82 loc) · 3.77 KB
/
Paint.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
from Tkinter import *
class Paint(Frame):
def __init__(self, parent):
Frame.__init__(self, parent)
self.parent = parent
self.color = "black"
self.brush_size = 2
self.setUI()
def set_color(self, new_color):
self.color = new_color
def set_brush_size(self, new_size):
self.brush_size = new_size
def draw(self, event):
self.canv.create_oval(event.x - self.brush_size,
event.y - self.brush_size,
event.x + self.brush_size,
event.y + self.brush_size,
fill=self.color, outline=self.color)
def drawCircle(self,newX,newY,newColor,newBrushSize):
self.canv.create_oval(newX-newBrushSize,
newY-newBrushSize,
newX + newBrushSize,
newY + newBrushSize,
fill=newColor, outline=newColor)
def setUI(self):
self.parent.title("MyTrajectoryPaint")
self.pack(fill=BOTH, expand=1)
self.columnconfigure(6, weight=1)
self.rowconfigure(2, weight=1)
self.canv = Canvas(self, bg="white")
self.canv.grid(row=2, column=0, columnspan=7,
padx=5, pady=5, sticky=E+W+S+N)
self.canv.bind("<B1-Motion>", self.draw)
color_lab = Label(self, text="Color: ")
color_lab.grid(row=0, column=0, padx=6)
def setNewUI(self):
red_btn = Button(self, text="Red", width=10,
command=lambda: self.set_color("red"))
red_btn.grid(row=0, column=1)
green_btn = Button(self, text="Green", width=10,
command=lambda: self.set_color("green"))
green_btn.grid(row=0, column=2)
blue_btn = Button(self, text="Blue", width=10,
command=lambda: self.set_color("blue"))
blue_btn.grid(row=0, column=3)
black_btn = Button(self, text="Black", width=10,
command=lambda: self.set_color("black"))
black_btn.grid(row=0, column=4)
white_btn = Button(self, text="White", width=10,
command=lambda: self.set_color("white"))
white_btn.grid(row=0, column=5)
clear_btn = Button(self, text="Clear all", width=10,
command=lambda: self.canv.delete("all"))
clear_btn.grid(row=0, column=6, sticky=W)
size_lab = Label(self, text="Brush size: ")
size_lab.grid(row=1, column=0, padx=5)
one_btn = Button(self, text="Two", width=10,
command=lambda: self.set_brush_size(2))
one_btn.grid(row=1, column=1)
two_btn = Button(self, text="Five", width=10,
command=lambda: self.set_brush_size(5))
two_btn.grid(row=1, column=2)
five_btn = Button(self, text="Seven", width=10,
command=lambda: self.set_brush_size(7))
five_btn.grid(row=1, column=3)
seven_btn = Button(self, text="Ten", width=10,
command=lambda: self.set_brush_size(10))
seven_btn.grid(row=1, column=4)
ten_btn = Button(self, text="Twenty", width=10,
command=lambda: self.set_brush_size(20))
ten_btn.grid(row=1, column=5)
twenty_btn = Button(self, text="Fifty", width=10,
command=lambda: self.set_brush_size(50))
twenty_btn.grid(row=1, column=6, sticky=W)
def main():
root = Tk()
root.geometry("850x500+100+100")
app = Paint(root)
root.mainloop()
if __name__ == '__main__':
main()
#main()