def button(self,msg,x,y,w,h,inactive_color,active_color, action=None):
clicked = False
for event in self.event_queue:
if event.type == pygame.MOUSEBUTTONDOWN:
clicked = True
mouse = pygame.mouse.get_pos()
if x+w > mouse[0] > x and y+h > mouse[1] > y:
pygame.draw.rect(self.screen, active_color,(x,y,w,h))
if clicked and action is not None:
action()
else:
pygame.draw.rect(self.screen, inactive_color,(x,y,w,h))
font = pygame.font.SysFont('monospace', 25)
textSurf, textRect = self.textObjects(msg, font, [255,255,255])
textRect.center = ( (x+(w/2)), (y+(h/2)) )
self.screen.blit(textSurf, textRect)
评论列表
文章目录