Python + Pygame; screen.fill()崩溃的窗口

问题描述 投票:0回答:1

[每当我尝试在我的pygame代码中包含“ screen.fill(在此处插入值)”时,窗口立即崩溃。我可以将其注释掉,而我的代码也可以正常工作。我真的不确定为什么。

[我已经尝试过使用其他人的代码来移动这条线,但是没有运气。

import pygame
pygame.init()

win = pygame.display.set_mode((1000, 800))
pygame.display.set_caption("Tetris")

img=pygame.image.load("C:\\Users\\Charlotte\\Desktop\\tetris_grid.png")
win.blit(img,(450, 150))

running = True
while running:
    screen.fill(0, 0, 0)
    pygame.display.update()
    pygame.time.delay(100)

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            run = False

pygame.quit()

当我运行包含该行的代码时,窗口将打开,然后立即关闭。

python background pygame screen fill
1个回答
1
投票

如果您试图用黑色填充屏幕,则必须将颜色作为元组传递:

win.fill((0, 0, 0))

而且,您从不分配screen,也许您打算使用win

Surface.fill的文档。

© www.soinside.com 2019 - 2024. All rights reserved.