【问题标题】:How can I add multiple variables to a label text?如何将多个变量添加到标签文本?
【发布时间】:2018-09-02 12:51:29
【问题描述】:

我真的是 python 新手,所以我真的很感激一些帮助。 这是我的意思的一个例子:

from tkinter import*
root=Tk()
a='I'
b='like'
c='programming'
lbl=Label(root,text=a'.',b'.',c,'.')
lbl.pack()

mainloop()

这是我要输出的内容:

I.like.programming.

【问题讨论】:

  • Python3.6+ 中的 f 字符串:text=f'{a}.{b}.{c}.'

标签: python python-3.x tkinter


【解决方案1】:

您可以添加字符串。如果变量不是字符串,则将其转换为字符串,然后添加它们。

from tkinter import*
root=Tk()
a='I'
b='like'
c='programming'
lbl=Label(root,text=a+'.'+b+'.'+c+'.')
lbl.pack()

mainloop()

输出:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-03-30
    • 2021-07-11
    • 2019-07-16
    • 2016-05-25
    • 2021-05-18
    • 1970-01-01
    • 1970-01-01
    • 2020-09-06
    相关资源
    最近更新 更多