Python 我 运行 没反应

Python Not Responding when I Run it

Python播放没反应。也没有出现语法错误。不知道哪里出了问题。我尝试了 运行 我制作的另一款游戏,运行良好,所以我认为这不是我的电脑。 error message

这是我的代码:

import pygame 

pygame.init()

screen = pygame.display.set_mode((800,600))

pygame.display.set_caption("Draft")

icon = pygame.image.load("doctor.png")

pygame.display.set_icon(icon)

white = (255,255,255)
black = (0,0,0) red = (255,0,0)
green = (0,255,0)
blue = (0,0,255)

def draw_ground():
    groundx = 20
    groundy = 30
    Ground = pygame.Rect(groundx,groundy,width = 800,height = 20)
    pygame.draw.rect(screen,green,Ground)

running = True
while running:

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

    draw_ground()

还没有完成,我正在尝试先测试一下再继续。

您的代码中有错别字:

black = (0,0,0) red = (255,0,0)

必须

black = (0,0,0) 
red = (255,0,0)

然而,还有更多。


pygame.Rect 不接受关键字参数:

Ground = pygame.Rect(groundx,groundy,width = 800,height = 20)

Ground = pygame.Rect(groundx,groundy,800,20)

您必须通过调用 pygame.display.update() or pygame.display.flip():

来更新显示
clock = pygame.time.Clock()
running = True
while running:
    clock.tick(60)
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

    # clear dispaly
    screen.fill(0)

    # draw objects
    draw_ground()

    # update dispaly
    pygame.display.flip()

典型的 PyGame 应用程序循环必须: