Python 无法使用tkinter中的justify和anchor命令控制标签中文本的位置。

Python 无法使用tkinter中的justify和anchor命令控制标签中文本的位置。,python,tkinter,Python,Tkinter,我无法控制标签的文本。我正在使用place定位这些标签 下面是我的示例代码 from tkinter import * root = Tk() root.geometry('1080x640+0+0') Headings = ['Months','Days','* Occupancy','Energy \nConsumption','Fuel \nConsumption', 'Specific Fuel \nConsumption','Diesel Price','Specific Ene

我无法控制标签的文本。我正在使用place定位这些标签

下面是我的示例代码

from tkinter import *

root = Tk()
root.geometry('1080x640+0+0')


Headings = ['Months','Days','* Occupancy','Energy \nConsumption','Fuel \nConsumption', 'Specific Fuel \nConsumption','Diesel Price','Specific Energy \nConsumption']
Units = ['2017','per month','man days/month','kWh/month','Litres','Litres/kWh','AED','kWh/man/day']
Headings_wd = [0,0,0,0,0,0,0,0]
Units_wd = [0,0,0,0,0,0,0,0]

for a in range(0,len(Headings)):
    Headings_wd[a] = Label(root, text = Headings[a], justify = LEFT )
    Headings_wd[a].place(x = 20 + a * 100, y = 20)
    Units_wd[a] = Label(root, text = Units[a], anchor = 'e' , font = ("Helvetica" , 6) )
    Units_wd[a].place(x = 20 + a * 100, y = 60)

root.mainloop()
我想在标签的最右边有
单位的
标签
我该怎么办


我曾尝试在本网站上的先前答案中使用命令
Units\u wd[a].config(borderwidth=1,relief=“solid”)
进行调试,但当我使用
place

时,这些命令不起作用。如注释中所述,通过使用
width
命令来获得所需的结果,问题得以解决

Headings_wd[a] = Label(root, text = Headings[a], width = 10, anchor = 'e')

Units_wd[a] = Label(root, text = Units[a], width = 10, anchor = 'e' , font = ("Helvetica" , 6) )

感谢注释中提到的@WhatstThePoint

,通过使用
width
命令获得所需结果,问题得以解决

Headings_wd[a] = Label(root, text = Headings[a], width = 10, anchor = 'e')

Units_wd[a] = Label(root, text = Units[a], width = 10, anchor = 'e' , font = ("Helvetica" , 6) )

感谢@WhatstThePoint

这是因为您的标签刚好有足够的空间来填充文本,如果您使用
width
属性使标签大于文本的最大大小,那么您可以使用
justify=RIGHT
将其向右移动。我强烈建议您不要使用
place
。要使GUI看起来美观、对大小调整、字体更改和不同分辨率做出良好响应要困难得多,如果使用
width
属性使标签大于文本的最大大小,则可以使用
justify=RIGHT
将其向右移动。我强烈建议您不要使用
place
。要使GUI看起来美观,并对大小调整、字体更改和不同分辨率做出良好响应要困难得多。