Pygame shows a black screen
The window opens but stays black or blank. The cause is almost always in your drawing order, a missing display update, or something covering what you drew.
On this page
1. Is pygame.display.flip() called?#
Everything you draw goes to an off-screen buffer. Nothing is visible until pygame.display.flip() (or pygame.display.update()) runs. It must be inside the loop, once per frame, after all drawing.
2. Is the order fill → draw → flip?#
screen.fill("black") # 1. clear
pygame.draw.circle(screen, "gold", (320, 240), 40) # 2. draw
pygame.display.flip() # 3. showIf fill() comes after your drawing, it paints over everything. Check helper functions too: a draw_background() called last has the same effect.
3. Are you drawing where you think?#
- Off-screen positions: a sprite at
(800, 100)in a 640-wide window isn't visible. Print the position. - Same colour as the background: black text on a black screen.
- A Rect with zero size:
pygame.Rect(100, 100, 0, 0)draws nothing. - Wrong Surface: drawing onto a separate Surface that's never blitted to
screen. If you callset_mode()a second time, the oldscreenSurface is no longer displayed.
4. Is the image actually visible?#
- An image with an all-transparent alpha channel, or drawn with
set_alpha(0), is invisible. convert()on an image with transparency replaces transparent areas with black. Useconvert_alpha()for PNGs with transparency.- Text rendered with the background colour as the text colour won't show.
5. Is the loop running at all?#
If an exception happens before the first flip(), the window may appear black briefly and close, or stay black while the terminal shows a traceback. Read the terminal output. If the window also says "Not Responding", see window not responding.
6. Platform-specific causes#
- Fullscreen on multi-monitor systems can show a black screen while the mode changes. Try windowed mode first, or
pygame.SCALED | pygame.FULLSCREEN. - Remote desktops and virtual machines may lack accelerated graphics. Setting the environment variable
SDL_RENDER_DRIVER=softwarebefore starting can help when usingSCALED. - Outdated graphics drivers occasionally cause blank windows with
SCALEDorOPENGL. Update drivers or test without those flags.
A minimal test#
If nothing works, run this. If it shows a gold circle, Pygame and your display are fine and the problem is in your code.
import pygame
pygame.init()
screen = pygame.display.set_mode((400, 300))
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
screen.fill("navy")
pygame.draw.circle(screen, "gold", (200, 150), 50)
pygame.display.flip()
pygame.quit()