如何解决Pygame图标和标题不会更新问题是什么?
在我的代码中,标题和图标更新不起作用。我有pygame 1.9.6,python 3.8和png文件是32.32。我的代码是:
import pygame
pygame.init()
screen = pygame.display.set_mode((800,600)
pygame.display.set_caption("Space Invader")
icon = pygame.image.load('ufo.png')
pygame.display.set_icon(icon)
playerImg = pygame.image.load('player.png')
playerX = 370
playerY = 480
def player():
screen.blit(playerImg,(playerX,playerY))
running = True
while running:
colour = (255,0)
screen.fill(colour)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
pygame.display.update()
解决方法
缺少)
:
screen = pygame.display.set_mode((800,600)
screen = pygame.display.set_mode((800,600))
您必须在主应用程序循环中而不是循环之后更新显示。更正Indentation:
while running:
# [...]
#-->| INDENTATION
pygame.display.update()
[...]某些系统不允许在显示窗口图标后对其进行更改。可以在
pygame.display.set_mode()
之前调用此函数,以在设置显示模式之前创建图标。
在screen = pygame.display.set_mode((800,600))
之前设置图标:
pygame.display.set_caption("Space Invader")
icon = pygame.image.load('ufo.png')
pygame.display.set_icon(icon)
screen = pygame.display.set_mode((800,600))
工作代码:
import pygame
pygame.init()
pygame.display.set_caption("Space Invader")
icon = pygame.image.load('ufo.png')
pygame.display.set_icon(icon)
screen = pygame.display.set_mode((800,600))
playerImg = pygame.image.load('player.png')
playerX = 370
playerY = 480
def player():
screen.blit(playerImg,(playerX,playerY))
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
colour = (255,0)
screen.fill(colour)
player()
pygame.display.update()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。