text displays on screen only when I click to exit the program

Quentin Bock qberz2005 at gmail.com
Fri Apr 30 14:55:55 EDT 2021


code with comments for context:

#Create a text based game where the user must find 3 items before
completing a level
#imports and variables for game
import pygame
from pygame import mixer
running = True
#initializes pygame
pygame.init()

#creates the pygame window
screen = pygame.display.set_mode((1200, 800))

#Title and Icon of window
pygame.display.set_caption("3.02 Project")
icon = pygame.image.load('3.02 icon.png')
pygame.display.set_icon(icon)

#setting up font
pygame.font.init()
font = pygame.font.Font('C:\Windows\Fonts\OCRAEXT.ttf', 16)
font_x = 10
font_y = 40
items_picked_up = 0
items_left = 3

#functions to be called later in program
def display_instruction(x, y):
    instructions = font.render("Each level contains 3 items you must pick
up in each room."
                               "When you have picked up 3 items, you will
advance to the next room, there are 3 rooms.", True, (255, 255, 255))
    screen.blit(instructions, (10, 40))

def main():
    global running

    #Game Loop
    while running:
        #sets screen color to black
        screen.fill((0, 0, 0))

        #checks if the user quits or exits the window
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                running = False

    display_instruction(font_x, font_y)
    pygame.display.update()


main()



please excuse the def main() thing, this doesn't follow a tutorial this is
all on my own, and I don't know why the text displays when I close the
python window.
I appreciate all help :)

<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=icon>
Virus-free.
www.avast.com
<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=link>
<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>


More information about the Python-list mailing list