Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
no screen is generated
#1
hello I’ve got this issue. I run the program I dont see the new screen that is supposed to be generated although program runs. I’ve googled for almost 2hrs and tried bunch of stuff but none of them worked or maybe I've placed them wrongly. I have W10 and newest Python and I'm a complete noob.

# first PyGame
 
 
# přístup do knihovny PyGame
import pygame
 
import pygame.display
pygame.display.init()
 
# velikost okna
SCREEN_WIDTH = 800
SCREEN_HEIGHT = 800
SCREEN_TITLE = "Krosovka"
 
# barvy RGB
WHITE_COLOR = (255, 255, 255)
BLACK_COLOR = (0, 0, 0)
# Clock k aktualizaci eventů a frames
clock = pygame.time.Clock()
pygame.font.init()
font = pygame.font.SysFont('comicsans', 75)
 
class Game:
 
 
 
    # FPS
    TICK_RATE = 60
 
 
    def __init__(self, title, width, height):
        self.title = title
        self.width = width
        self.height = height
 
       
        # vytvoří okno dle specifikace
        self.game_screen = pygame.display.set_mode((width, height))
        # vybarví okno bíle
        self.game_screen.fill(WHITE_COLOR)
        pygame.display.set_caption(title)
       
    # hlavní herní LOOP
    def run_game_loop(self):
        is_game_over = False
 
is_game_over = False
 
while not is_game_over:
 
        # LOOP, který kontroluje eventy
        # Myš, klávesnice...
        for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    is_game_over = False
                         
                   
                print(event)
 
   
   
# updatuje GRAFIKU
pygame.display.update()
       
# zapnutí FPS
clock.tick(TICK_RATE)
 
 
 
new_game = Game(SCREEN_TITLE, SCREEN_WIDTH, SCREEN_HEIGHT)
new_game.run_game_loop()
 
 
 
 
 
 
 
 
 
pygame.quit()
 
 
    # nakreslí čtverec (kde, barva, x, y, šířka, výška
    ## pygame.draw.rect(game_screen, BLACK_COLOR, [350, 350, 100, 100])
    # nakreslí kruh (kde, barva, x, y, (poloměr))
    ## pygame.draw.circle(game_screen, BLACK_COLOR, (400, 300), 50)
 
    # umístění obrázku
    ## game_screen.blit(player_image, (375, 375))
 
    # nahrát obrázek
    ## player_image = pygame.image.load("player.png")
    # zvětšení obrázku
    ## player_image = pygame.transform.scale(player_image, (50, 50))
thanks for your help
Reply
#2
you had your while loop dedented not within the run_game_loop method properly. You can also just use pygame.init() to initialize every module.

# first PyGame
 
 
# přístup do knihovny PyGame
import pygame

pygame.init()
 
#import pygame.display
#pygame.display.init()
 
# velikost okna
SCREEN_WIDTH = 800
SCREEN_HEIGHT = 800
SCREEN_TITLE = "Krosovka"
 
# barvy RGB
WHITE_COLOR = (255, 255, 255)
BLACK_COLOR = (0, 0, 0)
# Clock k aktualizaci eventů a frames
clock = pygame.time.Clock()
#pygame.font.init()
font = pygame.font.SysFont('comicsans', 75)
 
class Game:
 
 
 
    # FPS
    TICK_RATE = 60
 
 
    def __init__(self, title, width, height):
        self.title = title
        self.width = width
        self.height = height
 
       
        # vytvoří okno dle specifikace
        self.game_screen = pygame.display.set_mode((width, height))
        # vybarví okno bíle
        self.game_screen.fill(WHITE_COLOR)
        pygame.display.set_caption(title)
       
    # hlavní herní LOOP
    def run_game_loop(self):
        is_game_over = False
 
        is_game_over = False
         
        while not is_game_over:
         
            # LOOP, který kontroluje eventy
            # Myš, klávesnice...
            for event in pygame.event.get():
                    if event.type == pygame.QUIT:
                        is_game_over = True
                             
                       
                    print(event)
         
           
           
            # updatuje GRAFIKU
            pygame.display.update()
               
            # zapnutí FPS
            clock.tick(60)
 
 
 
new_game = Game(SCREEN_TITLE, SCREEN_WIDTH, SCREEN_HEIGHT)
new_game.run_game_loop()
 
 
 
 
 
 
 
 
 
pygame.quit()
 
 
    # nakreslí čtverec (kde, barva, x, y, šířka, výška
    ## pygame.draw.rect(game_screen, BLACK_COLOR, [350, 350, 100, 100])
    # nakreslí kruh (kde, barva, x, y, (poloměr))
    ## pygame.draw.circle(game_screen, BLACK_COLOR, (400, 300), 50)
 
    # umístění obrázku
    ## game_screen.blit(player_image, (375, 375))
 
    # nahrát obrázek
    ## player_image = pygame.image.load("player.png")
    # zvětšení obrázku
    ## player_image = pygame.transform.scale(player_image, (50, 50))
Recommended Tutorials:
Reply
#3
HOLY hell thank you so much!!!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyGame] When I hit the space bar from the home screen, it sends me to the game over screen JesusisKing 1 976 Apr-30-2023, 10:11 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020