Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/286.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 Pygame文本未呈现_Python_Text_Pygame_Render - Fatal编程技术网

Python Pygame文本未呈现

Python Pygame文本未呈现,python,text,pygame,render,Python,Text,Pygame,Render,好的,我正在用python和pygame制作一个选择题问答游戏。但是,我已经完成了开始屏幕,并尝试创建问题屏幕。我就是不明白为什么文本不能呈现。这是我的密码: enter_pressed = False random_question = random.randrange(1, 3) question_number = 0 # Sets the height and width of the screen size = [720, 575]

好的,我正在用python和pygame制作一个选择题问答游戏。但是,我已经完成了开始屏幕,并尝试创建问题屏幕。我就是不明白为什么文本不能呈现。这是我的密码:

    enter_pressed = False

    random_question = random.randrange(1, 3)
    question_number = 0

    # Sets the height and width of the screen
    size = [720, 575] 
    screen = pygame.display.set_mode((size),pygame.FULLSCREEN)

    # The Caption for the display
    pygame.display.set_caption("Quiz")

    # Function that automatically renders text
    def render_text(word, x, y, font, size, color):
        # Itinitialize font
        my_font = pygame.font.SysFont(font, size) 
        # Renders font
        label = my_font.render(word, 1, (color))
        screen.blit(label, (x, y))

    # Loops until the user clicks the close button
    done = False
    clock = pygame.time.Clock()

    # While loop
    while not done:

        # Leaves the fps at 30
        clock.tick(30)

        for event in pygame.event.get(): # If user did something
            if event.type == pygame.QUIT: # If user clicked close
                done = True
            elif event.type == pygame.KEYDOWN: # If user pressed a key
                if event.key == pygame.K_RETURN: # If user pressed enter
                    # Makes the start screen go away
                    enter_pressed = True
                    # Increments question_number
                    question_number += 1

                    **#This is what won't render!!!
                    render_text("Stud", 200, 200, "Arial", 30, BLACK)**

        # Set the screen background
        screen.fill(BACKGROUND)

        # Removes start screen
        if enter_pressed == False:

            # Where drawing happens
            pygame.draw.rect(screen, WHITE, [285, 237, 150, 100])

            # Renders START
            render_text("START", 287, 260, "Arial", 45, BLACK)

            # Renders Celebrity Car Museum:
            render_text("Quiz", 165, 80, "Cooper std", 50, BLACK)

            # Renders Car Quiz
            render_text("Quiz", 285, 150, "Cooper std", 50, BLACK)

            # Renders Press ENTER to start
            render_text("Press ENTER to start", 282, 350, "Impact", 20, BLACK)

        # Update the screen
        pygame.display.flip()

您正在渲染文本并立即清理屏幕


不要在处理事件时绘制,只需更新游戏状态,然后绘制该状态。就像你在
enter\u pressed==False
中所做的那样,你应该在那里放置一个
else
并呈现你的文本。

谢谢,我忘记了填充背景不仅可以设置背景,还可以清理屏幕。