[英]Pygame background not blitting
I'm just learning GUI programming using python 3.2 and pygame 1.8. 我正在学习使用python 3.2和pygame 1.8的GUI编程。 From what I understand the following code should display a white background. 据我了解,以下代码应显示白色背景。 However all I get is a black screen. 但是我得到的只是一个黑屏。 Also, I'm using IDLE in Windows 7 if that matters: 另外,如果这很重要,我将在Windows 7中使用IDLE:
import pygame
pygame.init()
screen = pygame.display.set_mode((640, 480))
background = pygame.Surface(screen.get_size())
background.fill((255, 255, 255))
screen.blit(background, (0, 0))
You must have a main loop that updates the screen. 您必须具有更新屏幕的主循环。 This code should work: 这段代码应该有效:
import pygame
pygame.init()
screen = pygame.display.set_mode((640, 480))
background = pygame.Surface(screen.get_size())
background.fill((255, 255, 255))
while True:
screen.blit(background, (0, 0))
pygame.display.update()
You forgot to update the screen. 您忘记更新屏幕了。
import pygame
pygame.init()
screen = pygame.display.set_mode((640, 480))
background = pygame.Surface(screen.get_size())
background.fill((255, 255, 255))
screen.blit(background, (0, 0))
pygame.display.update()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
You don't blit the backgound you just put the fill part in the loop. 您无需将背景填充,只需将填充部分放入循环中即可。 Also you are forgetting the pygame.display.update()
你也忘记了pygame.display.update()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.