如何將 Tkinter Text 小元件中的文字居中?
Tkinter 文字小元件是一個多行文字輸入小元件。它用於在輸入欄位中插入、刪除和新增文字資料。它在小元件類中提供了許多內建函式和屬性。
要配置文字並將其對齊到 Tkinter Text 小元件的 CENTER,我們可以使用 **justify=CENTER ** 屬性。
示例
# Import the required libraries
from tkinter import *
# Create an instance of tkinter frame or window
win=Tk()
# Set the size of the window
win.geometry("700x350")
text=Text(win)
# Configure the alignment of the text
text.tag_configure("tag_name", justify='center')
# Insert a Demo Text
text.insert("1.0", "How do I center align the text " "in a Tkinter Text widget?")
# Add the tag in the given text
text.tag_add("tag_name", "1.0", "end")
text.pack()
win.mainloop()輸出
執行以上程式碼以顯示一個視窗,其中一個示例文字置於 Text 小元件的中心。
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
安卓
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP