Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/336.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python screen.fill不';好像不行_Python - Fatal编程技术网

Python screen.fill不';好像不行

Python screen.fill不';好像不行,python,Python,我已经编写了一个游戏,一切正常,所以现在我想要的是游戏开始前的屏幕。然后必须单击“开始”继续游戏。到目前为止,我有以下代码: if menu == 'start': screen.fill((0,255,0)) txt = font.render('Start',True,(255,255,0)) txt_x = 480 txt_y = 290 buttonrect = pygame.Rect((txt_x,txt_y),txt.get_size())

我已经编写了一个游戏,一切正常,所以现在我想要的是游戏开始前的屏幕。然后必须单击“开始”继续游戏。到目前为止,我有以下代码:

if menu == 'start':
    screen.fill((0,255,0))
    txt = font.render('Start',True,(255,255,0))
    txt_x = 480
    txt_y = 290
    buttonrect = pygame.Rect((txt_x,txt_y),txt.get_size())
    pygame.draw.rect(screen,(0,0,255),buttonrect)
    screen.blit(txt,(txt_x,txt_y))
    if pygame.mouse.get_pressed()[0] and buttonrect.collidepoint(pygame.mouse.get_pos()):
        menu = 'game'

我已将菜单设置为“开始”,但它不起作用。屏幕是黑色而不是绿色。但当我点击坐标时,我就去玩游戏了。我的代码有什么问题?

设置屏幕背景后,需要更新主显示:

if menu == 'start':
    screen.fill((0,255,0))
    txt = font.render('Start',True,(255,255,0))
    txt_x = 480
    txt_y = 290
    buttonrect = pygame.Rect((txt_x,txt_y),txt.get_size())
    pygame.draw.rect(screen,(0,0,255),buttonrect)
    screen.blit(txt,(txt_x,txt_y))

    pygame.display.update()

    if pygame.mouse.get_pressed()[0] and buttonrect.collidepoint(pygame.mouse.get_pos()):
        menu = 'game'

设置屏幕背景后,您需要更新主显示:

if menu == 'start':
    screen.fill((0,255,0))
    txt = font.render('Start',True,(255,255,0))
    txt_x = 480
    txt_y = 290
    buttonrect = pygame.Rect((txt_x,txt_y),txt.get_size())
    pygame.draw.rect(screen,(0,0,255),buttonrect)
    screen.blit(txt,(txt_x,txt_y))

    pygame.display.update()

    if pygame.mouse.get_pressed()[0] and buttonrect.collidepoint(pygame.mouse.get_pos()):
        menu = 'game'