im trying to create a game where it needs a username and password to be able to login. I have only created an input for the letter "w" just to make the code a lot smaller. my problem is that if I press the w key it won't pop up on the display, but then all of a sudden 2-4 "w"s pop up after the word "hello". I don't understand why this happens
thanks in advance
import pygame
FPS = 60
black = (0, 0, 0)
white = (255, 255, 255)
blue = (0, 0, 255)
cyan = (0, 255, 255)
grey = (150, 150, 150)
brown = (139, 69, 19)
lBrown = (235, 188, 128)
peach = (255, 211, 129)
selected_colour = (0, 0, 0)
#height of game display
height = 960
#width of game display
width = 960
game_display = pygame.display.set_mode((height, width))
pygame.display.set_caption("Chess")
pygame.font.init()
font = pygame.font.SysFont("calibri", 30)
clock = pygame.time.Clock()
Login = True
username = "hello"
def update_fps():
fps_counter = str(int(clock.get_fps()))
fps_text = font.render(fps_counter, 1, pygame.Color("coral"))
return (fps_text)
Typing = False
gameRunning = True
while gameRunning:
pygame.display.flip()
game_display.fill(white)
game_display.blit(update_fps(), (910, 0))
clock.tick(FPS)
mouse_x, mouse_y = pygame.mouse.get_pos()
for event in pygame.event.get():
if event.type == pygame.QUIT:
gameRunning = False
if Login:
pygame.draw.rect(game_display, black, (330, 400, 300, 100),5)
font = pygame.font.SysFont("calibri", 30)
if mouse_x >= 330 and mouse_x <= 630 and mouse_y >= 400 and mouse_y <= 500:
if event.type == pygame.MOUSEBUTTONDOWN:
#Login = False
#mainPage = True
Typing = True
if mouse_x <= 330 and mouse_x >= 630 and mouse_y <= 400 and mouse_y >= 500:
if event.type == pygame.MOUSEBUTTONDOWN:
Typing = False
if Typing:
for event in pygame.event.get():
pressed = pygame.key.get_pressed()
if pressed[pygame.K_w]:
print("w is pressed")
username = username + "w"
if pressed[pygame.K_BACKSPACE]:
username[:-1]
game_display.blit(font.render(username, True, selected_colour), (410, 625))