显示风上的Pygame显示变量

2024-05-17 02:53:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用Pygame,并且已经知道如何在屏幕上显示文本。但是我如何让它为一个变量工作,所以它不会显示“Hello”,而是显示我的变量。例如,假设我有一个变量,我想在显示面板上显示它/对它所做的任何更改。所以如果变量是1,并且添加了1,我想显示更改后的变量。

#Dice random number generation
diceRoll = random.randrange(0, 5)

#Text through GUI
myFont = pygame.font.SysFont("Times New Roman", 18)

randNumLabel = myFont.render("You have rolled:", 1, black)
diceDisplay = myFont.render(diceRoll, 1, black)

screen.blit(randNumLabel, (520, 20))
screen.blit(diceDisplay, (520, 30))

pygame.display.flip()

Tags: 文本面板hello屏幕randomrenderscreenpygame