pygame square跟随鼠标光标

riv*_*ues 5 python pygame

当我运行一个pygame程序时,一个白色方块(大约15px乘15px)跟随我的光标在窗口周围.这发生在最基本的pygame程序和其他一些程序上.我最基本的pygame程序:

import pygame, sys

DISPLAYSURF = pygame.display.set_mode((500,500))
clock = pygame.time.Clock()


while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()

    pygame.display.update()

    # --- Limit to 60 frames per second
    clock.tick(30)
Run Code Online (Sandbox Code Playgroud)

为什么会这样?是我的代码,我的系统还是Pygame?我正在运行python 3.7,pygame 1.9.4和macOS 10.13.6.

编辑:在Crouton(linux)上运行相同的程序后,没有正方形.

小智 0

我在我的电脑上尝试了你的代码,效果很好,所以我不确定发生了什么,但你可以尝试以下操作:

  1. 第二行输入命令 pygame.init()
  2. 将 pygame.display.update() 替换为 pygame.display.flip()