小编Tej*_*s K的帖子

如何检查鼠标是否在某个区域被点击(pygame)

我正在尝试在 pygame 中编写一个程序,如果在某个区域按下鼠标,它将打印一些内容。我尝试过使用 mouse.get_pos 和 mouse.get_pressed 但我不确定我是否正确使用它们。这是我的代码

while True:
    DISPLAYSURF.fill(BLACK)
        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit()
                sys.exit()
            mpos = pygame.mouse.get_pos()
            mpress = pygame.mouse.get_pressed()
            if mpos[0] >= 400 and mpos[1] <= 600 and mpress == True:
                print "Switching Tab"
Run Code Online (Sandbox Code Playgroud)

python pygame

2
推荐指数
1
解决办法
6702
查看次数

标签 统计

pygame ×1

python ×1