我想将文本左对齐,但 anchor='w'
似乎不起作用...
有什么建议吗?
from tkinter import Tk, Label
window = Tk()
lab = Label(window, text = 'hey', anchor='w')
lab2 = Label(window, text='hellooooooo', anchor='w')
lab.grid(column=0, row=0)
lab2.grid(column=0, row=1)
window.mainloop()
最佳答案
不要使用anchor属性,而是使用网格布局的sticky属性。修改后的粘性代码如下。
from tkinter import Tk, Label
window = Tk()
lab = Label(window, text = 'hey')
lab2 = Label(window, text='hellooooooo')
lab.grid(column=0, row=0, sticky='w')
lab2.grid(column=0, row=1, sticky='w')
window.mainloop()
希望这段代码能够实现您想要的功能。
关于python - 使用 Tkinter 将文本左对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59193645/