这是我的代码:
import pygame
# Initialize
pygame.init()
screenInfo = pygame.display.Info()
displayWidth = screenInfo.current_w # 1920 on my pc
displayHeight = screenInfo.current_h # 1080 on my pc
gameDisplay = pygame.display.set_mode((displayWidth, displayHeight), pygame.FULLSCREEN)
quit_game = False
def HandleEvents():
"""
Handle quit requests from user
"""
global quit_game
for event in pygame.event.get():
if event.type == pygame.QUIT or (event.type == pygame.KEYDOWN and event.key == pygame.K_q):
quit_game = True
while not quit_game:
HandleEvents()
gameDisplay.fill((0, 0, 0))
pygame.draw.circle(gameDisplay, (255, 255, 255), (displayWidth/2, displayHeight/2), 20)
pygame.display.update()
当我运行它时,白色圆圈会按预期出现在屏幕中间,但是当我通过按alt + esc切换到另一个窗口,然后通过按其图标重新进入程序时,白色圆圈会移动到正确,并保持这种方式,无论我再次重新输入多少程序。