Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在画布上检查鼠标位置时出错(Pygame)_Python_Tuples_Pygame - Fatal编程技术网

Python 在画布上检查鼠标位置时出错(Pygame)

Python 在画布上检查鼠标位置时出错(Pygame),python,tuples,pygame,Python,Tuples,Pygame,我的代码应该检查我的鼠标位置,然后打印出来,但它只检查一次,有什么问题 import pygame, sys, time from pygame.locals import * pygame.init() WINDOW_WIDTH = 1000 WINDOW_HEIGHT = 600 surface = pygame.display.set_mode ((WINDOW_WIDTH, WINDOW_HEIGHT),0,32) pygame.display.set_caption ('get P

我的代码应该检查我的鼠标位置,然后打印出来,但它只检查一次,有什么问题

import pygame, sys, time 
from pygame.locals import *

pygame.init()
WINDOW_WIDTH = 1000
WINDOW_HEIGHT = 600
surface = pygame.display.set_mode ((WINDOW_WIDTH, WINDOW_HEIGHT),0,32)
pygame.display.set_caption ('get POS')

while True:
    amntTuple = pygame.mouse.get_pos()
    print (amntTuple)
    time.sleep(0.2)

您需要建立并设置适当的pygame事件处理循环。

您需要建立并设置适当的pygame事件处理循环。

调用以从pygame事件队列获取新事件

while True:
    for event in pygame.event.get():    
        amntTuple = pygame.mouse.get_pos()
        print (amntTuple)
调用以从pygame事件队列获取新事件

while True:
    for event in pygame.event.get():    
        amntTuple = pygame.mouse.get_pos()
        print (amntTuple)