在Tkinter中创建标签的问题 [英] Problems with creating label in tkinter
问题描述
我在tkinter中创建了简单的标签,但是它是用{}创建的,我不想这样做.
I create simple label in tkinter but it is created with {}, what I don't want to.
gameOver=Label(root, text=('Game over!\nYou scored', number, ' points!'),
font=('Arial Black', '26'), bg='red')
这是我的代码,其中number
是可变的.但它显示"{游戏结束!您得分} 0 {点!}"
这段代码就是这样(0是number
的值)
That is my code, where number
is variable. But it prints "{Game over! You scored} 0 {points!}"
That is what get with this code (0 is value of number
)
欢迎提出解决此问题的任何想法
Any ideas to solve this problem are welcome
推荐答案
('Game over!\nYou scored', number, ' points!')
是三个元素的元组,但是text
可能希望使用字符串,并对其他类型的参数执行奇怪的操作.使用字符串串联或format
提供单个字符串.
('Game over!\nYou scored', number, ' points!')
is a tuple of three items, but text
probably expects a string instead, and does strange things to arguments of other types. Use string concatenation or format
to provide a single string.
gameOver=Label(root, text='Game over!\nYou scored' + str(number) + ' points!',
font=('Arial Black', '26'), bg='red')
或
gameOver=Label(root, text='Game over!\nYou scored {} points!'.format(number),
font=('Arial Black', '26'), bg='red')
这篇关于在Tkinter中创建标签的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!