文本对齐方式
- 左对齐(left):默认对齐方式,文本从左边界开始。
- 右对齐(right):文本从右边界开始。
- 居中对齐(center):文本在水平中心对齐。
效果

代码
import tkinter as tkdef main():root = tk.Tk()root.title("Tkinter 文本对齐示例")text = tk.Text(root, width=40, height=10)text.pack()text.insert(tk.END, "这是左对齐的文本。\n", "left")text.tag_configure("left", justify='left')text.insert(tk.END, "这是居中对齐的文本。\n", "center")text.tag_configure("center", justify='center')text.insert(tk.END, "这是右对齐的文本。\n", "right")text.tag_configure("right", justify='right')text.insert(tk.END, "\n额外的左对齐文本。\n", "left")text.insert(tk.END, "额外的居中对齐文本。\n", "center")text.insert(tk.END, "额外的右对齐文本。\n", "right")root.mainloop()if __name__ == "__main__":main()