Luk*_*ka1 0 python label tkinter
我在tkinter中创建了简单的标签,但它是用{}创建的,我不想这样做.
gameOver=Label(root, text=('Game over!\nYou scored', number, ' points!'),
font=('Arial Black', '26'), bg='red')
Run Code Online (Sandbox Code Playgroud)
这是我的代码,其中number是可变的.但它打印出"{Game over!you scored} 0 {points!}"这就是用这段代码得到的(0是值number)

任何解决这个问题的想法都是受欢迎的
('Game over!\nYou scored', number, ' points!')是一个由三个项组成的元组,但text可能需要一个字符串,并对其他类型的参数做一些奇怪的事情.使用字符串连接或format提供单个字符串.
gameOver=Label(root, text='Game over!\nYou scored' + str(number) + ' points!',
font=('Arial Black', '26'), bg='red')
Run Code Online (Sandbox Code Playgroud)
要么
gameOver=Label(root, text='Game over!\nYou scored {} points!'.format(number),
font=('Arial Black', '26'), bg='red')
Run Code Online (Sandbox Code Playgroud)