簡體   English   中英

Tkinter 和 Python3 - 如何在 label 小部件中證明多行文本的合理性?

[英]Tkinter and Python3 - How Can I justify a multiple lines text in a label widget?

我在 ttk label 中有一個由多行組成的文本。 默認情況下,文本從左邊框到右邊框顯示,沒有任何“對齊”選項。 我的目標是在所有 label 上傳播文本。 我不想在右側、左側、中心等對齊文本。我想證明它的合理性,尤其是當您證明 Microsoft Word 中的文本時。 我怎樣才能達到我的目標?

您可以使用tkinter.ScrolledText模塊:

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就是這樣制作的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM