0
我只想讓這個模子滾動一次,但是當我點擊空間時它會滾動50次。怎麼了!?這個模具爲什麼會滾動多次?
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit(); sys.exit()
pygame.display.update()
if event.type == pygame.KEYDOWN and event.key == pygame.K_SPACE:
diceRoll = random.randint(1, 4)
diceRollLabel = myFont.render(str(diceRoll), 1, black)
window.blit(diceRollLabel, (580, 35))
print("Dice roll test", diceRoll)
pygame.display.update()
下面的代碼,因爲它最初發布:
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit(); sys.exit()
pygame.display.update()
if event.type == pygame.KEYDOWN and event.key == pygame.K_SPACE:
diceRoll = random.randint(1, 4)
diceRollLabel = myFont.render(str(diceRoll), 1, black)
window.blit(diceRollLabel, (580, 35))
print("Dice roll test", diceRoll)
pygame.display.update()
你把空格鍵放下嗎? – JeremyFromEarth
請修正您的帖子中的縮進。正如所寫,它不會運行。至少有一種可能的方式來縮進它以使其運行會導致你看到的問題。 – abarnert
我不認爲有人應該試圖解決OP的縮進問題。我很確定不正確的縮進是真正的問題,所以改變他發佈的內容隱藏了相關信息。 – abarnert