在Tkinter中创建标签的问题 [英] Problems with creating label in tkinter

查看:124
本文介绍了在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆