Reputation: 71
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')
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
Upvotes: 0
Views: 211
Reputation: 76184
('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')
Or
gameOver=Label(root, text='Game over!\nYou scored {} points!'.format(number),
font=('Arial Black', '26'), bg='red')
Upvotes: 5