# button.py from graphics import * class Button: def __init__(self,win,center,width=70,height=40,label="EXIT"): """ win : graphics window, center: point where the button is centered, width: width of the button, 70 by default, height: heght of the button,40 by default, label: button's label, EXIT by default """ self.win = win self.x_min = center.getX() - width / 2 self.y_min = center.getY() - height / 2 self.x_max = center.getX() + width / 2 self.y_max = center.getY() + height / 2 self.br = Rectangle(Point(self.x_min,self.y_min),Point(self.x_max,self.y_max)) self.bt = Text(center,label) self.deactivate() self.br.draw(win) self.bt.draw(win) self.active = False def deactivate(self): """ the button is not active """ self.br.setFill("green") self.br.setWidth(1) self.active = False def activate(self): """ activate the button """ self.br.setFill("green2") self.br.setWidth(2) self.active = True def clicked(self,p): """ returns True if the point p is inside the button """ return self.x_min <=p.getX() <= self.x_max and self.y_min <=p.getY() <= self.y_max def getLabel(self): """ returns button's label """ return self.bt.getText()