1

I am using pygame to create a keyboard game and my code just stops after this function ends. This is the code of the function:

import pygame 
from sys import exit
def HomePage():
  clock = pygame.time.Clock()
  screen = pygame.display.set_mode((500,400)) 
  Homepage_Image = pygame.image.load('Textures/Homepage/homepage.png')
  Homepage_Image_Done = pygame.transform.scale(Homepage_Image, (500, 400))
  Play_Button = pygame.image.load('Textures/Homepage/play.png')
  Play_Button_Done = pygame.transform.scale(Play_Button, (200,375))
  Options_Button = pygame.image.load('Textures/Homepage/Options.png')
  Options_Button_Finished = pygame.transform.scale(Options_Button, (200,375))
  Sign_In_Button = pygame.image.load('Textures/Homepage/Sign_In.png')
  Sign_In_Button_Finished = pygame.transform.scale(Sign_In_Button, (200,375))
  Quit_Button = pygame.image.load('Textures/Homepage/Quit.png')
  Quit_Button_Finished = pygame.transform.scale(Quit_Button, (200,375))
  Sign_Up_Button = pygame.image.load('Textures/Homepage/Sign_Up.png')
  Sign_Up_Button_Finished = pygame.transform.scale(Sign_Up_Button,(200,375))
  running = True
  while (running):
    screen.blit(Homepage_Image_Done,(0,0))
    screen.blit(Play_Button_Done,(140,150))
    screen.blit(Options_Button_Finished, (0,-75))
    screen.blit(Sign_In_Button_Finished, (0,50))
    screen.blit(Quit_Button_Finished, (325,-75))
    screen.blit(Sign_Up_Button_Finished, (305,43))
    pygame.display.update()
    clock.tick(90)
    for event in pygame.event.get():
        if event.type == pygame.KEYDOWN:
          if event.key == pygame.K_q:
            running = False
            exit()
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_s:
                print('Start')
                running = False
                break
        if event.type == pygame.KEYDOWN:
          if event.key == pygame.K_a:
            print('Sign In')
            running = False
            break
        if event.type == pygame.KEYDOWN:
          if event.key == pygame.K_o:
            print('Options')
            running = False
            break
        if event.type == pygame.KEYDOWN:
          if event.key == pygame.K_m:
            print('Sign Up')
            running = False
    continue

When I run it in my other file where the code looks like this:

import pygame
from sys import exit
from HomePage import HomePage
from time import sleep
from pygame import mixer
from replit import audio
#imports for nerds

#source = audio.play_file("Sounds/music1.mp3")
Icon = pygame.image.load('Textures/icon.png')
pygame.display.set_icon(Icon)
axe_count = 0
pickaxe_count = 0
wood_block = 0
height = 400
width = 500
pygame.init()

screen = pygame.display.set_mode((width,height)) 
#Screen display
pygame.display.set_caption("Tools 'n Brix") 
#Window Title
clock = pygame.time.Clock()

HomePage()

It doesn't continue after I click one of the buttons that should open a new window once I continue the code (A, M, S, O and Q)

The_spider
  • 455
  • 2
  • 9
Magic Tax
  • 11
  • 1
  • *"[...] should open a new window once i continue the code [...]"* Where exactly do you think you are trying to open a window? I can't see any code to open a window after the `HomePage` function returns. – Rabbid76 Nov 25 '21 at 05:30
  • See [Python debugging tips](https://stackoverflow.com/questions/1623039/python-debugging-tips) – Rabbid76 Nov 28 '21 at 22:26

0 Answers0