如何将文字对齐到左边?

Ser*_*gey 7 python tkinter

请帮助修复脚本.

from tkinter import *
colors = ['red',  'white',  'blue']

def packbox(root):
    Label(root, text='Pack').pack()
    for color in colors:
        row = Frame(root)
        lab = Label(row, text=color, relief=RIDGE,  width=25)
        ent = Entry(row, bg=color,   relief=SUNKEN, width=50)
        row.pack(side=TOP,   expand=YES, fill=BOTH)
        lab.pack(side=LEFT,  expand=YES, fill=BOTH)
        ent.pack(side=RIGHT, expand=YES, fill=BOTH)

root = Tk()
packbox(root)
mainloop()
Run Code Online (Sandbox Code Playgroud)

我想在左边缘的Label小部件中对齐文本

afk*_*ion 13

试试这个

Label(root, text='Pack', anchor='w').pack(fill='both')
Run Code Online (Sandbox Code Playgroud)

  • 关于为什么它有效的一些解释会比仅仅表达更好。 (10认同)

Gou*_*war 9

锚点用于定义文本相对于参考点的位置。

这是可能的常量列表,可用于 Anchor 属性。

NW

N

NE

W

CENTER

E

SW

S

SE
Run Code Online (Sandbox Code Playgroud)