我无法在使用 Label
生成的输出中插入新行在 Tkinter 中。下面是我的 GUI 的图像,它解释了我的问题。
这是我用来定义标签的代码。
string1 = 'At pathID' + str(l.get('pathId'))+
'In label' + str(keys) +':'+
'profile in reference but not in copy' +
str(list(set(a_value)-set(b_value)))
ttk.Label(t.sub_frame, text=string1).pack(side="left", fill="x", expand=1)
我想要什么:
我想在 At path ID0 in label.....
的开头换一个新行
因此标签中的输出应如下所示,而不是如 GUI 图像中上面一行所示:
At path ID0 In label1: profile in reference but not in copy[(18,0,0)]
At path ID0 In label2: profile in reference but not in copy[(18,0,8)]
我尝试过的:
上面显示的行是在循环中生成的,因此我尝试在行开始之前保留换行符,但它只显示下一行的输出,但将其附加在一行中。
string1 = '\n' + '\nAt pathID' + str(l.get('pathId'))+
'In label' + str(keys) +':'+
'profile in reference but not in copy' +
str(list(set(a_value)-set(b_value)))
我假设的原因是在每个循环中都会遇到新行字符,并且我可以以换行符打印每一行。你们能给我推荐一些东西吗?我想我在某个地方遗漏了一个小逻辑
最佳答案
我不明白为什么,但由于某些原因,pack
中的值导致了一些问题。我编辑了我的代码,如下所示。现在它工作正常。
ttk.Label(t.sub_frame, text=string1).pack()
谢谢大家的关注。
关于Python - 在 Tkinter 标签中插入新行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31854556/