如何将变量放入标签文本? [英] How to put variable into a label text?
本文介绍了如何将变量放入标签文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我写了一个带有标签的tkinter代码.标签文本中有一个变量.
I wrote a tkinter code, with a label. There was a variable in the label text.
lab = Label(root, text = 'randomstrings', x, 'randomstrings')
lab.pack()
运行代码时,它在此处显示错误消息:,x,
When I ran the code, it gave an error message here: , x,
它说:位置参数紧跟关键字参数
It said: positional argument follows keyword argument
推荐答案
在将所有标签块传递到Label
之前,必须将所有标签块放在一起:
You must put all label pieces together before passing them to the Label
:
Label(root, text = 'randomstrings' + str(x) + 'randomstrings', ...)
或:
Label(root, text = 'randomstrings{}randomstring'.format(x), ...)
这篇关于如何将变量放入标签文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文