-
Notifications
You must be signed in to change notification settings - Fork 3
/
Button.py
24 lines (18 loc) · 875 Bytes
/
Button.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
try:
import simplegui
except ImportError:
import SimpleGUICS2Pygame.simpleguics2pygame as simplegui
class Button:
def __init__(self, image, pos, trigger):
self.image = simplegui.load_image(image)
self.pos = pos
self.trigger = trigger
self.clicked = False
def draw(self, canvas):
canvas.draw_image(self.image, (self.image.get_width() / 2, self.image.get_height() / 2),(self.image.get_width(), self.image.get_height()), self.pos,(self.image.get_width(), self.image.get_height()))
def contains(self, pos):
return self.pos[0] - (self.image.get_width() / 2) < pos[0] < self.pos[0] + (self.image.get_width() / 2) and \
self.pos[1] - (self.image.get_height() / 2) < pos[1] < self.pos[1] + (self.image.get_height() / 2)
def clickBtn(self):
self.clicked = True
self.trigger()