Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Graphics
  4. Pygame image wont show up until I close the window

Pygame image wont show up until I close the window

Scheduled Pinned Locked Moved Graphics
game-devannouncement
3 Posts 3 Posters 29 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    c0d3r1 2
    wrote on last edited by
    #1

    I am creating a game with pygame and an image won't show up until the window is loading to be closed. This is my code so far:

    import pygame

    pygame.init()
    screen = pygame.display.set_mode((800, 600))

    pygame.display.set_caption("ALix")
    icon = pygame.image.load("nater.jpg")
    pygame.display.set_icon(icon)

    playerImg = pygame.image.load('nater.jpg')
    playerX = 400
    playerY = 300

    def player():
    screen.blit(playerImg, (playerX, playerY))

    running = True
    while running:
    screen.fill((255, 255, 255))

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
    

    player()

    pygame.display.update()

    L 1 Reply Last reply
    0
    • C c0d3r1 2

      I am creating a game with pygame and an image won't show up until the window is loading to be closed. This is my code so far:

      import pygame

      pygame.init()
      screen = pygame.display.set_mode((800, 600))

      pygame.display.set_caption("ALix")
      icon = pygame.image.load("nater.jpg")
      pygame.display.set_icon(icon)

      playerImg = pygame.image.load('nater.jpg')
      playerX = 400
      playerY = 300

      def player():
      screen.blit(playerImg, (playerX, playerY))

      running = True
      while running:
      screen.fill((255, 255, 255))

      for event in pygame.event.get():
          if event.type == pygame.QUIT:
              running = False
      

      player()

      pygame.display.update()

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      I do not know pygame but I notice that you do not call pygame.display.update() until the end of the program. In most GUI applications you need to call update during normal running in order to keep it current.

      F 1 Reply Last reply
      0
      • L Lost User

        I do not know pygame but I notice that you do not call pygame.display.update() until the end of the program. In most GUI applications you need to call update during normal running in order to keep it current.

        F Offline
        F Offline
        Faheem Lashari
        wrote on last edited by
        #3

        When running I am blit'ing some text onto my surface (WIN) and I want this to be shown in the game so I call pygame.display.update to update the display, this works perfectly fine until the loop has iterated around 75 times and after this the display stops updating. Code below

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups