UPDATED CODE:
import pygame
pygame.init()
width = 700
height = 700
running = True
screen = pygame.display.set_mode((width, height))
pygame.display.set_caption("Dijkstra's Path-Finding Algorithm Solver")
icon = pygame.image.load('icon.jpg')
pygame.display.set_icon(icon)
def title_main():
title_font = pygame.font.Font('TrajanPro-Regular.otf', 40)
text_font = pygame.font.SysFont("comicsans", 30, bold=True)
Dijkstra_img = pygame.image.load('Dijkstra.jpg')
text1_display = title_font.render("Dijkstra's Path-Finding", True, (255, 255, 255))
text2_display = title_font.render('Algorithm', True, (255, 255, 255))
text3_display = text_font.render('Press any key to continue...', True, (255, 255, 255))
screen.blit(Dijkstra_img, (225, 40))
screen.blit(text1_display, (75, 400))
screen.blit(text2_display, (225, 460))
screen.blit(text3_display, (190, 550))
def title_game():
title_font = pygame.font.Font('TrajanPro-Regular.otf', 35)
title_display = title_font.render('Dijkstra Path-Finding Algorithm', True, (255, 255, 255))
screen.blit(title_display, (12, 15))
def title_underline():
rect = pygame.Rect(0, 60, 800, 3)
rect_display = pygame.draw.rect(screen, [255, 255, 255], rect)
title_font = pygame.font.Font('TrajanPro-Regular.otf', 100)
title_display = title_font.render('', True, (255, 255, 255))
screen.blit(title_display, (270, 198))
def grid():
grid_x = 0
grid_y = 63
blockSize = 20
for x in range(width):
for y in range(height):
rect = pygame.Rect(x*blockSize + grid_x, y*blockSize + grid_y, blockSize, blockSize)
pygame.draw.rect(screen, (200,200,200), rect, 1)
def game_loop():
game_is_active = True
while game_is_active:
for game_event in pygame.event.get():
if game_event.type == pygame.QUIT:
game_is_active = False
if game_event.type == pygame.MOUSEBUTTONDOWN:
start = print(pygame.mouse.get_pos())
print(start)
screen.fill((0, 0, 0))
title_game()
title_underline()
grid()
pygame.display.update()
while running:
for event in pygame.event.get():
screen.fill((0, 0, 0))
title_main()
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
running = game_loop()
pygame.display.update()
I have created a title page for my project under a function that I run when I start the GUI, but what I want to do is that when the user presses any key, I want to NOT display the title_main() function anymore and just display my main application instead. I used KEYDOWN to try to do this but for some reason, its very slow and non-responsive and also the title_main() function still is displayed.