【问题标题】:Tkinter anchor option not working with multiline stringTkinter 锚选项不适用于多行字符串
【发布时间】:2021-07-30 13:42:21
【问题描述】:

我想在我的 GUI 中有一个标签,文本左对齐。我尝试使用anchor,但如果字符串由多行组成,它似乎不起作用。 我的代码如下所示:

lbl_welcome = tk.Label(fr_welcome, anchor = 'w', text = "First line\n and this is the second")

标签和框架位于西北方向,使用sticky。 我得到的看起来像这样: GUI with the label

这里标签/文本框向左对齐,但不是文本本身。它可以正常工作,但是对于不存在 \n 的单行字符串。

【问题讨论】:

    标签: python tkinter label anchor


    【解决方案1】:

    默认情况下,每行都居中。如果您希望文本左对齐,则需要使用 justify 选项。

    lbl_welcome = tk.Label(..., justify="left")
    

    【讨论】:

      猜你喜欢
      • 2015-01-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-10
      • 2017-01-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多