Tkinter 文本居左对齐:使用 anchor 和 tag_configure
要设置 Tkinter 文本居左,可以使用 'anchor' 参数将文本锚定到左侧。
下面是一个示例代码:
import tkinter as tk
root = tk.Tk()
text = tk.Text(root, width=30, height=10)
text.pack()
text.insert('end', 'This is a left-aligned text.
', 'left')
text.tag_configure('left', justify='left')
root.mainloop()
在这个示例中,我们创建了一个文本框,并将文本插入其中。然后,我们为文本框的内容添加了一个标签 'left',并使用 'tag_configure' 方法设置该标签的对齐方式为左对齐。
这样,文本就会显示为左对齐了。
原文地址: http://www.cveoy.top/t/topic/hSlM 著作权归作者所有。请勿转载和采集!