A.E*_*ami 4 python tkinter alignment
在Python的Tkinter中:我有一个带有不同标签的表.我如何证明标签中的文字是正确的?因为它是一张桌子,不同标签的文字汇集在一起!
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)
Run Code Online (Sandbox Code Playgroud)
我想要一些东西在中心证明标签中的一些文字,但它不是我需要的东西plz检查这个:链接
Bry*_*ley 17
默认情况下,标签中的文本以标签为中心.您可以使用anchor属性控制它,也可以使用属性控制它justify.justify仅当窗口小部件中有多行文本时才会影响文本.
例如,要使标签内的文本右对齐,您可以使用anchor="e":
a=Label(root,text='Hello World!', anchor="e")
Run Code Online (Sandbox Code Playgroud)
但请注意,如果标签足够大以容纳文本,则此效果似乎无效.在您的具体示例中,您需要为每个标签指定相同的宽度:
a=Label(..., width=12)
b=Label(..., width=12)
Run Code Online (Sandbox Code Playgroud)
小智 11
补充一下 Bryan 所说的,LEFT是您正在寻找的常量,以正确设置换行文本的格式。您还可以证明RIGHTor CENTER(默认值)。
a=Label(root,text='Hello World!', anchor="e", justify=LEFT)
Run Code Online (Sandbox Code Playgroud)
而不是使用.pack()我将使用.grid() http://effbot.org/tkinterbook/grid.htm
网格可以更好地管理您的组件
在下面找到用法和管理的示例:
Label(root, text="First").grid(row=0, sticky=W)
Label(root, text="Second").grid(row=1, sticky=W)
entry1 = Entry(root)
entry1 = Entry(root)
entry1.grid(row=0, column=1)
entry2.grid(row=1, column=1)
checkbutton.grid(columnspan=2, sticky=W)
image.grid(row=0, column=2, columnspan=2, rowspan=2,
sticky=W+E+N+S, padx=5, pady=5)
button1.grid(row=2, column=2)
button2.grid(row=2, column=3)
Run Code Online (Sandbox Code Playgroud)
您最终将使用网格选项padx =“ x”来“对齐”标签
| 归档时间: |
|
| 查看次数: |
29223 次 |
| 最近记录: |