Pygame Window 打开然后立即关闭
Pygame Window opens then immediately cloeses
经过大约一个半月的休息后,我将回到 pygame。
我试图打开并创建一个 window 我试图 运行 它并且 window 立即关闭。
这是所有代码:
import pygame
pygame.init()
screen_x = 230
screen_y = 230
display = pygame.display.set_mode ((screen_x, screen_y))
我正在使用 VSCode 如果有什么用的话,这是我第一次使用 VSCode 所以如果我做错了什么我可能不知道。
您需要一个事件循环,否则应用程序将立即关闭。
以下是执行此操作的一些起始代码:
import pygame
# screen object(width,height)
screen_x = 230
screen_y = 230
screen = pygame.display.set_mode((screen_x, screen_y))
# Set the caption of the screen
pygame.display.set_caption('Title')
# Variable to keep our game loop running
running = True
# game loop
while running:
# for loop through the event queue
for event in pygame.event.get():
# Check for QUIT event
if event.type == pygame.QUIT:
running = False
经过大约一个半月的休息后,我将回到 pygame。 我试图打开并创建一个 window 我试图 运行 它并且 window 立即关闭。 这是所有代码:
import pygame
pygame.init()
screen_x = 230
screen_y = 230
display = pygame.display.set_mode ((screen_x, screen_y))
我正在使用 VSCode 如果有什么用的话,这是我第一次使用 VSCode 所以如果我做错了什么我可能不知道。
您需要一个事件循环,否则应用程序将立即关闭。 以下是执行此操作的一些起始代码:
import pygame
# screen object(width,height)
screen_x = 230
screen_y = 230
screen = pygame.display.set_mode((screen_x, screen_y))
# Set the caption of the screen
pygame.display.set_caption('Title')
# Variable to keep our game loop running
running = True
# game loop
while running:
# for loop through the event queue
for event in pygame.event.get():
# Check for QUIT event
if event.type == pygame.QUIT:
running = False