我正在尝试使用锚点将标签中的文本向右对齐,如下所示:
label=Label(root, text="some text", anchor='e', width=50)它只适用于一行。但由于某些原因,当文本超过一行时,它只适用于最长的一行,而其他行相对最长的一行居中。为什么会发生这种情况?我该如何解决这个问题呢?example
发布于 2020-05-03 09:40:22
所以我认为你的问题在于你使用的是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() 因此,这是可行的,并证明了文本的正当性。
希望这能有所帮助!
https://stackoverflow.com/questions/61568320
复制相似问题