This repository has been archived by the owner on May 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buttonClass.py
93 lines (71 loc) · 2.11 KB
/
buttonClass.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
####
# Button object
class Butt(object):
def __init__(self,cx,cy,w,h,label):
self.cx = cx # x of central point of button
self.cy = cy # y of central point of button
self.w = w # width of button
self.h = h # height of button
self.label = label # text on the button
self.color = 'black' # button color
self.labCol = 'black' # label color
def isInside(self, curX, curY): # x,y: the current position of mouse
lowerBoundX = self.cx - self.w/2
upperBoundX = self.cx + self.w/2
lowerBoundY = self.cy - self.h/2
upperBoundY = self.cy + self.h/2
return (lowerBoundX < curX < upperBoundX) and \
(lowerBoundY < curY < upperBoundY)
def promptChange(self):
self.color = 'gold2'
self.labCol = 'black'
def changeBack(self):
self.color = 'black'
self.labCol = 'black'
def magicPrompt(self, curX, curY):
if self.isInside(curX, curY):
self.promptChange()
else:
self.changeBack()
def showButton(self,canvas):
x, y = self.cx, self.cy
halfW = self.w/2
halfH = self.h/2
color = self.color
label = self.label
labelColor = self.labCol
canvas.create_rectangle(x-halfW, y-halfH, x+halfW, y+halfH, fill =color)
canvas.create_text(x, y, text=label, fill = labelColor, font = 'impact 25')
class Control(Butt):
def __init__(self,cx,cy,w,h,label):
super().__init__(cx,cy,w,h,label)
self.color = 'black'
self.labCol = 'white'
def promptChange(self):
self.color = "white"
self.labCol = "black"
def changeBack(self):
self.color = 'black'
self.labCol = 'white'
class Elegant(Butt):
def __init__(self,cx,cy,w,h,label):
super().__init__(cx,cy,w,h,label)
self.color = 'pale goldenrod'
self.labCol = 'black'
def promptChange(self):
self.color = "goldenrod"
self.labCol = "black"
def changeBack(self):
self.color = 'pale goldenrod'
self.labCol = 'black'
class Bloody(Butt):
def __init__(self,cx,cy,w,h,label):
super().__init__(cx,cy,w,h,label)
self.color = 'red4'
self.labCol = 'black'
def promptChange(self):
self.color = "firebrick3"
self.labCol = "black"
def changeBack(self):
self.color = 'red4'
self.labCol = 'black'