对齐按钮中的文本

Aligning Text in Buttons

from tkinter import *

root = Tk()
Button(root, text="sldkjf", justify=LEFT, padx=130).pack()

root.mainloop()

为什么我把对齐设置为 left,但左边没有显示文字?

justify 选项的文档是这样说的:

justify - When there are multiple lines of text displayed in a widget, this option determines how the lines line up with each other.

你没有多行,你只有一行。

要使文本与顶部、底部、左侧或右侧对齐,您需要使用 anchor 选项。文档是这样说的:

anchor - Specifies how the information in a widget (e.g. text or a bitmap) is to be displayed in the widget. Must be one of the values n, ne, e, se, s, sw, w, nw, or center. For example, nw means display the information such that its top-left corner is at the top-left corner of the widget.

因此,在您的情况下,您应该使用 anchor="w"

您还有一个问题,即两侧都应用了过多的内边距,实际上是挤压文本以适应左侧 130x 内边距和右侧 130px 内边距之间的大小。如果删除填充,文本将锚定到小部件的左侧。