Skip to content
← Back to Community
Help to create the screen
Profile icon
asidick

Hi
I am a beginner to pygame and i am learning the basics. if someone can help me please.The screen keeps disappearing...
Thanks..

Voters
Profile icon
KeenanWillard
Profile icon
AV4CAD0
Profile icon
asidick
Comments
hotnewtop
Profile icon
AV4CAD0

First, you need to import a few more modules:

from pygame.locals import * import sys

You should also change line 6 to:

pygame.display.set_caption("Number One")

The reason that your windows disappears is because the game exits immediately as you have no game loop.
You should add this:

fpsClock = pygame.time.Clock() while True: # Main game loop for event in pygame.event.get(): if event.type == QUIT: # This is when you close the window pygame.quit() sys.exit() pygame.display.flip() # Update the display - not actually # needed here but it is in most games fpsClock.tick(20) # Change the number to edit the speed of your # game in frames per second.

Hope I helped! :)

Profile icon
Bookie0

Here this is what I found on the internet,

import pygame background_colour = (255,255,255) (width, height) = (300, 200) screen = pygame.display.set_mode((width, height)) pygame.display.set_caption('Practice') screen.fill(background_colour) pygame.display.flip() running = True while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False