如何将 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