Python Forum
no screen is generated - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Game Development (https://python-forum.io/forum-11.html)
+--- Thread: no screen is generated (/thread-16306.html)



no screen is generated - senfik99 - Feb-22-2019

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


RE: no screen is generated - metulburr - Feb-22-2019

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))



RE: no screen is generated - senfik99 - Feb-22-2019

HOLY hell thank you so much!!!