Your issue is here:
while running:
dt = clock.tick(60)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
answer = ""
guessed = [] # <-----ISSUE
Everytime the while loop starts over, you're assigning the guessed list to an empty list. What you need to do is place the guessed = []
before the while like this:
import pygame
pygame.init()
running = True
window_width = 600
window_height = 600
window = pygame.display.set_mode((window_width, window_height))
clock = pygame.time.Clock()
word = "something"
guessed = []
while running:
pygame.display.update() # <---- Needs to be called every loop passing to update the window
dt = clock.tick(60)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
answer = ""
guessed.append(input("write your letter here -> "))
for i in word:
if i in guessed:
answer += i + " "
else:
answer += "_ "
print(answer)
answer = ""
pygame.quit()
You also need to update your window every time the while loop goes by. I added it in the code I provided above.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…