-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathButtons.py
39 lines (33 loc) · 1.64 KB
/
Buttons.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
try: from cmu_cs3_graphics import *
except: from cmu_graphics import *
def getButtonClicked(buttonsList, mouseX, mouseY):
for index in range(len(buttonsList)):
button = buttonsList[index]
top = button['top']
left = button['left']
length = button['length']
height = button['height']
if left <= mouseX <= left+length and top <= mouseY <= top+height:
return index
return None
def setAllButtonHoverFalse(buttonsList):
for button in buttonsList:
button['hover']= False
def drawAllButtons(buttonsList):
for button in buttonsList:
drawButton1(button['msg'], button['left'], button['top'], hover = button['hover'],length = button['length'],height = button['height'])
def drawThisButton(button):
drawButton1(button['msg'], button['left'], button['top'], hover = button['hover'],length = button['length'],height = button['height'])
#button color
def drawButton1(msg, left, top, hover = False, length=150, height=50, color = rgb(169, 191, 241), fontSize =14, ):
centerX = left+length/2
centerY = top+height/2
if not hover:
drawRect(left,top, length, height, fill = None, border= color, )
drawLabel(msg, centerX, centerY, fill = color,size =fontSize,bold =True)
else:
drawRect(left,top, length, height, fill = color, border= color)
drawLabel(msg, centerX, centerY, fill = 'white',size =fontSize, bold =True)
def setButton(buttonList, msg, left, top, hover = False, length=150, height=50, ):
buttonDict = {'msg': msg, 'top': top, 'left': left, 'length': length, 'height':height, 'hover': hover, }
buttonList.append(buttonDict)