1

I need help!

I need to load the 'play' button in the menu, but it doesn't work and it just shows black screen. The code is here:

import pygame
start = False
play = pygame.image.load('game/play.png')
pygame.init()

win = pygame.display.set_mode((500,500))
pygame.display.set_caption('игра')

while run == True:
    pygame.time.delay(50)
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            run = False
    if start == False:
        win.blit(play, (0, 0))
Rabbid76
  • 202,892
  • 27
  • 131
  • 174
  • 2
    You missed [`pygame.display.flip()`](https://www.pygame.org/docs/ref/display.html#pygame.display.flip) or [`pygame.display.update`](https://www.pygame.org/docs/ref/display.html#pygame.display.update) – Rabbid76 Nov 02 '20 at 06:46
  • @Rabbid76 I did it like this, but it still has not been working: start = False play = pygame.image.load('game/play.png') pygame.init() win = pygame.display.set_mode((500,500)) pygame.display.set_caption('игра') pygame.display.update() while run == True: pygame.time.delay(50) for event in pygame.event.get(): if event.type == pygame.QUIT: run = False if start == False: win.blit(play, (0, 0)) – Артур Хачевич Nov 03 '20 at 06:48

1 Answers1

0

You missed to update the display by by either pygame.display.update() or pygame.display.flip(). You need to update the display at the end of the application loop after the scene has been drawn. Furthermore, I recommend that you clear the ad every frame:

import pygame
start = False
play = pygame.image.load('game/play.png')
pygame.init()

win = pygame.display.set_mode((500,500))
pygame.display.set_caption('игра')

while run == True:
    pygame.time.delay(50)
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            run = False

    # clear disaply
    win.fill(0)

    # draw scene (object)
    if start == False:
        win.blit(play, (0, 0))

    # update display
    pygame.display.flip()              # <--- add this
Rabbid76
  • 202,892
  • 27
  • 131
  • 174