【问题标题】:In tkinter, unable put label to the left, It remains in the middle在 tkinter 中,无法将标签放在左侧,它保留在中间
【发布时间】:2022-11-17 15:02:20
【问题描述】:

我的意思是我正在读取一个 txt 文件,对于 txt 文件中的每一行我 想要一个新标签。


root = tk.Tk()

#here it opens the file
with open("/file.txt", "r") as openedFile:

    allLines = openedFile.readlines()
    for line in allLines:
        textInLine = line

        testText = Label(root, text=textInLine)
        testText.pack()

root.geometry("400x300")
root.mainloop()

在文本文件中,行的长度不一样,所以它把标签文本水平居中,我希望它贴在最左边。

【问题讨论】:

    标签: python tkinter


    【解决方案1】:

    您可以使用 anchor 属性:

    testText.pack(anchor="w")
    

    w 表示“西”

    【讨论】:

    • 多谢兄弟。知道了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-07-16
    • 1970-01-01
    • 1970-01-01
    • 2018-01-17
    • 2020-03-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多