-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbutton.py
36 lines (29 loc) · 958 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
25
26
27
28
29
30
31
32
33
34
35
36
# -*- coding: utf-8 -*-
"""
Created on Tue Nov 30 20:46:25 2021
@author: leeds
"""
from graphics import *
class Button:
def __init__(self, picture):
center = picture.getAnchor()
width = picture.getWidth()
height = picture.getHeight()
self.image = picture
self.topLeft = Point(center.getX()-width//2, center.getY()-height//2)
self.botRight = Point(center.getX()+width//2, center.getY()+height//2)
def isClicked(self, click):
if click != None:
x = click.getX()
y = click.getY()
lX = self.topLeft.getX()
rX = self.botRight.getX()
tY = self.topLeft.getY()
bY = self.botRight.getY()
if (lX <= x <= rX) and (tY <= y <= bY):
return True
return False
def display(self, win):
self.image.draw(win)
def hide(self):
self.image.undraw()