小编Min*_*Bat的帖子

为什么 PyGame 中根本没有绘制任何内容?

我已经使用 pygame 在 python 中启动了一个新项目,对于背景,我希望下半部分填充灰色,顶部填充黑色。我以前在项目中使用过矩形绘图,但由于某种原因它似乎被破坏了?我不知道我做错了什么。最奇怪的是,每次运行程序的结果都不一样。有时只有黑色屏幕,有时灰色矩形覆盖屏幕的一部分,但永远不会覆盖屏幕的一半。

import pygame, sys
from pygame.locals import *
pygame.init()

DISPLAY=pygame.display.set_mode((800,800))
pygame.display.set_caption("thing")
pygame.draw.rect(DISPLAY, (200,200,200), pygame.Rect(0,400,800,400))

while True:
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()
Run Code Online (Sandbox Code Playgroud)

python pygame rectangles

6
推荐指数
1
解决办法
1748
查看次数

标签 统计

pygame ×1

python ×1

rectangles ×1