python 中的锚文本

Anchor text in python

我正在尝试使用锚点将标签中的文本像这样右对齐:

label=Label(root, text="some text", anchor='e', width=50)

一行就可以了。但出于某种原因,当文本长于一行时,它只适用于最长的一行,但其他行相对于最长的一行居中。 为什么会这样? 我该如何解决? example

所以我认为您的问题是您使用的是 anchor 而不是 justify

这两者的区别在于它们处理的文本行数。第一个影响一行文本 而后者影响不止一行文本。

所以我试了一下并且:

from tkinter import *


root = Tk()

myContainer1 = Frame(root)  
myContainer1.grid()         

label1 = Label(root, text = "Lorem Ipsum is simply dummy text of the printing and typesetting industry.\n" +
               "Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer\n" +
               "took a galley of type and scrambled it to make a type specimen book.\n" +
               "It has survived not only five centuries, but also the leap into electronic typesetting,\n"+
               "remaining essentially unchanged.",justify = 'right', width = 100 )

label1.grid(row = 0, column= 0)
root.mainloop()   

所以这行得通并证明了东边的文字。

希望对您有所帮助!