首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >python中的锚点文本

python中的锚点文本
EN

Stack Overflow用户
提问于 2020-05-03 08:54:58
回答 1查看 146关注 0票数 1

我正在尝试使用锚点将标签中的文本向右对齐,如下所示:

代码语言:javascript
运行
复制
label=Label(root, text="some text", anchor='e', width=50)

它只适用于一行。但由于某些原因,当文本超过一行时,它只适用于最长的一行,而其他行相对最长的一行居中。为什么会发生这种情况?我该如何解决这个问题呢?example

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-05-03 09:40:22

所以我认为你的问题在于你使用的是anchor而不是justify

这两种方法的不同之处在于它们操作了多少行文本。前者影响一行文本,而后者影响多行文本。

所以我试了一下,然后:

代码语言:javascript
运行
复制
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()   

因此,这是可行的,并证明了文本的正当性。

希望这能有所帮助!

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61568320

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档