如何在 Tkinter 中对齐标签中的文本 [英] How to justify text in label in Tkinter

查看:60
本文介绍了如何在 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)

这篇关于如何在 Tkinter 中对齐标签中的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆