python - python中的锚文本
问题描述
我正在尝试使用锚将标签中的文本向右对齐,如下所示:
label=Label(root, text="some text", anchor='e', width=50)
它适用于一条线。但由于某种原因,当文本长于一行时,它仅适用于最长的行,但其他行相对于最长的行居中。为什么会这样?我该如何解决? 例子
解决方案
所以我认为你的问题是你正在使用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()
因此,这有效并证明了东方的文本。
希望这可以帮助!
推荐阅读
- python - 使用负整数时,numpy bincount 的替代方法是什么?
- typescript - 打字稿:从对象中删除键
- reactjs - ReactJS 通过从服务器接收 json 创建组件
- php - 在 Laravel 中将刮板逻辑放在哪里?
- javascript - 仅在 API 查询成功后才提交表单以填充字段
- shell - 将列与行匹配
- r - 如何在 RStudio 中为 ggplot2 安装 Courier 字体
- c++ - 运行基于 SDL Cpp 的应用程序的问题
- swift - 如何在 MKMapView 上绘制自定义形状
- javascript - Angular Form 嵌套和条件字段问题