問題是,在您更新屏幕pygame.display.update()
後,您什麼都不做,程序就會結束。 pygame.display.update()
不會阻止。
您需要什麼通常稱爲主循環。這裏有一個事件處理的簡單例子:
import pygame
pygame.init()
picture = pygame.image.load("cards/S01.png")
# display.set_mode already returns the screen surface
screen = pygame.display.set_mode(picture.get_size())
# a simple flag to show if the application is running
# there are other ways to do this, of course
running = True
while running:
# it's important to get all events from the
# event queue; otherwise it may get stuck
for e in pygame.event.get():
# if there's a QUIT event (someone wants to close the window)
# then set the running flag to False so the while loop ends
if e.type == pygame.QUIT:
running = False
# draw stuff
screen.blit(picture, (0,0))
pygame.display.update()
這樣,你的應用程序不會,只有當有人關閉窗口。