首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Tkinter和Python3 -如何在标签小部件中对齐多行文本?

问Tkinter和Python3 -如何在标签小部件中对齐多行文本?
EN

Stack Overflow用户
提问于 2020-05-27 08:02:04
回答 1查看 421关注 0票数 2

我在ttk标签中有一个由多行组成的文本。默认情况下,文本从左边框到右边框显示,没有任何“对齐”选项。我的目标是在所有的标签上传播文字。我不想让文本右对齐、左对齐、居中对齐,等等。我想证明它,特别是当你在Microsoft Word中对齐一个文本时。我怎样才能达到我的目标?

EN

回答 1

Stack Overflow用户

发布于 2020-05-29 16:49:00

您可以使用tkinter.ScrolledText模块:

代码语言:javascript
复制
from tkinter import *
from tkinter.scrolledtext import *

win = Tk()

TEXT="""I have a text composed by multiple lines in a ttk label.
by default the text is displayed from the left border to right one without any kind of "justify" option.
My goal is spread the text on all the label. I don't want to align the text on the right, on the left, on the center, etc..
I want to justify it, exatly when you justify a text in Microsoft Word. how can I reach my goal?"""

text = ScrolledText(win, width=80, height=41, wrap=WORD) # create text zone
text.pack(expand=True, fill=BOTH) # pack it in the entire window
text.insert(1.0, TEXT)

win.mainloop()

通过添加tkinter.filedialog,你可以制作一个真正的记事本!

Python就是这样制作的。

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

https://stackoverflow.com/questions/62033360

复制
相关文章

相似问题

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