-1
產品圖更多,更清晰的問題: http://imgur.com/a/sbHaxPygame退格鍵輸入的文字未被清除。重疊而不是/
如圖所示,我輸入了一些文字。決定退格,而不是我輸入的新文本重疊前一個。這是爲什麼發生?
新來的Pygame並堅持了這個問題時間過長已經:(
請幫助!我應該做的
if not cheat:
WIN = pygame.image.load("Assets/winBox.png")
self.SCREEN.blit(WIN, (175, 230))
winRect = pygame.Rect(175, 230, 250, 164)
pygame.display.update(winRect)
done = False
while not done:
self.CLOCK.tick(self.FPS)
mouse = pygame.mouse.get_pos()
for event in pygame.event.get():
if event.type == pygame.QUIT:
self.STATE = 0
done = True
if 219 <= mouse[0] <= 269 and 366 <= mouse[1] <= 378 and pygame.mouse.get_pressed()[0] == 1:
# RESTART
self.STATE = 6
done = True
elif 311 <= mouse[0] <= 375 and 366 <= mouse[1] <= 378 and pygame.mouse.get_pressed()[0] == 1:
# MAIN MENU
self.STATE = 2
done = True
else:
WIN = pygame.image.load("Assets/winBoxWithScore.png")
self.SCREEN.blit(WIN, (175, 230))
winRect = pygame.Rect(175, 230, 250, 164)
pygame.display.update(winRect)
done = False
while not done:
self.CLOCK.tick(self.FPS)
mouse = pygame.mouse.get_pos()
for event in pygame.event.get():
if event.type == pygame.QUIT:
self.STATE = 0
done = True
if 219 <= mouse[0] <= 269 and 366 <= mouse[1] <= 378 and pygame.mouse.get_pressed()[0] == 1:
# RESTART
self.STATE = 6
done = True
if 311 <= mouse[0] <= 375 and 366 <= mouse[1] <= 378 and pygame.mouse.get_pressed()[0] == 1:
# MAIN MENU
self.STATE = 2
done = True
elif 290 <= mouse[0] <= 345 and 275 <= mouse[1] <= 325 and pygame.mouse.get_pressed()[0] == 1:
WIN = pygame.image.load("Assets/winBoxBlank.png")
self.SCREEN.blit(WIN, (175, 230))
winRect = pygame.Rect(175, 230, 250, 164)
pygame.display.update(winRect)
name = ""
done = False
while not done:
self.CLOCK.tick(self.FPS)
mouse = pygame.mouse.get_pos()
self.SCREEN.blit(
pygame.font.SysFont('comicsansms', 22).render("Enter your name :", True, Color.black),
(210, 250))
# Textbox
pygame.draw.rect(self.SCREEN, Color.gray, (210, 310, 180, 35), 2)
for event in pygame.event.get():
if event.type == pygame.QUIT:
self.STATE = 0
done = True
# Keyboard events
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_BACKSPACE:
name = name[:-1] # remove last char
elif event.key == pygame.K_RETURN or event.key == pygame.K_KP_ENTER:
done = True # break out of the while loop to return name
elif event.key == pygame.K_ESCAPE:
self.menu()
done = True
else:
try:
name += event.unicode # Append name
except:
pass
# Limit name to 10 characters
name = name[:10]
# Display characters typed
if len(name) != 0:
self.SCREEN.blit(pygame.font.SysFont('comicsansms', 22).render(name, True, Color.black),(230, 310))
pygame.display.update()
# Store score to the current textfile
p = Player(name, self.numdisks, str(len(self.moveList)))
with open("score.txt", "a") as sfile:
sfile.write("\n" + p.getName() + "\t" + str(p.getLevel()) + "\t" + str(p.getMove()))
# Navigate to the next page
self.STATE = 11
內如果舊文本沒有清除,那麼我想它不是」不需要更新。你是否在刪除字符時更新了文本框? – The4thIceman