Problems with creating label in tkinter

前端 未结 1 1492
时光取名叫无心
时光取名叫无心 2021-01-27 15:41

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!\'),         


        
相关标签:
1条回答
  • 2021-01-27 16:34

    ('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')
    
    0 讨论(0)
提交回复
热议问题