【发布时间】:2022-11-15 04:29:53
【问题描述】:
我想我是否可以像 create_variable 一样使用 Tkinter 显示变量。
player_score = 0
score = Canvas(window_game, width=300, height=40, bg="black")
score.create_text(50, 20, text="SCORE :", fill="white", font=('Courrier'))
score.grid(row=0,column=0) #x #y
lives = Canvas(window_game, width=300, height=40, bg="black")
lives.create_text(50, 20, text="LIVES :", fill="white", font=('Courrier'))
lives.grid(row=1,column=0)
您好,我想知道如何在“SCORE”旁边显示变量“payer_score”。 谢谢。
【问题讨论】:
-
您能否添加一个预期输入 -> 输出的示例?
-
为此,您可能会更好地将标签嵌入到画布中。否则,每次乐谱更改时,您都必须继续删除并重新创建文本。然而,要从最基本的意义上回答你的问题~使用fstrings:
f'SCORE: {player_score}'