如何在python中的tkinter中对齐标签中的文本需要在tkinter中对齐 [英] how to justify text in label in tkinter in python Need justify in tkinter
问题描述
在Python的Tkinter中:
我有一个带有不同标签的表。如何证明标签中的文字合理?因为它是一个表,并且不同标签中的文本在一起!
In Tkinter in Python: I have a table with a different label. How can I justify the text that is in the label? Because It is a table and the texts in different labels come together!
from tkinter import *
root=Tk()
a=Label(root,text='Hello World!')
a.pack()
a.place(x=200,y=200)
b=Label(root,text='Bye World')
b.pack()
b.place(x=200,y=100)
我想要一些用于使标签中某些文本居中对齐的东西,但我不需要,请检查以下内容:链接
I want something for justifying in center some text in label but it is not something that I need plz check this: link
推荐答案
默认情况下,文本标签中的标签位于标签的中心。您可以使用 anchor
属性,也可以使用 justify
属性进行控制。 justify
仅在小部件中有多行文本时才影响文本。
By default, the text in a label is centered in the label. You can control this with the anchor
attribute, and possibly with the justify
attribute. justify
only affects the text when there is more than one line of text in the widget.
例如,要使标签内的文本右对齐,可以使用 anchor = e
:
For example, to get the text inside a label to be right-aligned you can use anchor="e"
:
a=Label(root,text='Hello World!', anchor="e")
但是,请注意,如果标签正好足以容纳文本,则这似乎无效。在您的特定示例中,您需要为每个标签赋予相同的宽度:
Note, however, this will appear to have no effect if the label is exactly big enough to hold the text. In your specific example, you would need to give each label the same width:
a=Label(..., width=12)
b=Label(..., width=12)
这篇关于如何在python中的tkinter中对齐标签中的文本需要在tkinter中对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!