我想在 Python 中画一条线,但是当我运行下面的代码时,这条线永远不会出现。事实上,我需要制作一个具有 4x4 部分的字段,但让我们从一行开始。我的代码:
import sys, pygame
from pygame.locals import*
width = 1000
height = 500
screen_color = (49, 150, 100)
line_color = (255, 0, 0)
def main():
screen=pygame.display.set_mode((width,height))
screen.fill(screen_color)
pygame.display.flip()
pygame.draw.line(screen,line_color, (60, 80), (130, 100))
while True:
for events in pygame.event.get():
if events.type == QUIT:
sys.exit(0)
main()
怎么了?
原文由 J.Gor 发布,翻译遵循 CC BY-SA 4.0 许可协议
画线后,您必须使用
pygame.display.flip
更新计算机的显示。这通常在 while 循环的底部每帧完成一次。