touchscreen.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:openag_brain 作者: OpenAgInitiative 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号