我试图在pygame中制作一个程序,如果鼠标在某个区域被按下,它会打印出一些东西。我试过用mouse.get_pos以及鼠标。按下但我不确定我是否正确地使用了它们。这是我的密码
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"
使用^{} 来定义区域,检查是否在事件循环中按下了鼠标按钮,并使用
area
rect的collidepoint
方法来查看它是否与event.pos
(或者pygame.mouse.get_pos()
)相冲突。在在我的游戏中,我使用
MOUSEBUTTONDOWN
来检查鼠标按下:相关问题 更多 >
编程相关推荐