Python TkInter 标签结合文本变量和文本

1 投票
3 回答
5463 浏览
提问于 2025-04-18 05:05

我想用 seconds 字符串来打印运行时间。但是这段代码没有成功。

runTime = StringVar()
RT = Label(window, textvariable=runTime, text="seconds")
RT.pack()

输出结果:

0.00985...

我想把输出结果改成:

0.00985... seconds

3 个回答

-1

(来得有点晚)试试这个

runTime = ""
RT = Label(window, text=runTime + "seconds")
RT.pack()
1

这两个答案都不对。应该这样做:

time = tk.IntVar()
time.set(5)

runTime = tk.StringVar()

runTime.set(str(time .get()) + ' seconds')
1

试试这样做,

runTime = StringVar()
RT = Label(window, textvariable=runTime)
RT.pack()

runtime.set(str(<your time variable>)+'seconds')

撰写回答