简体   繁体   English

在python2.7中如何将文本与按钮对齐

[英]in python2.7 how to align the text with the button

in python 2.7 I'm trying to align the text frankie anne so its next to the name button and 27 so its next to the age button can only get them in center so far. 在python 2.7中,我正在尝试对齐文本Frankie Anne,以便其紧靠名称按钮和27,因此其紧靠age按钮只能使它们居中。 tried left and bottom already didn't work. 尝试左和底部已经不起作用。 any help would be helpful. 任何帮助都会有所帮助。

from Tkinter import *

root = Tk()

toolbar = Frame(root)

b = Button(toolbar, text="Home", width=9)
b.pack(side=LEFT, padx=2, pady=2)

b = Button(toolbar, text="About-us", width=9)
b.pack(side=LEFT, padx=2, pady=2)

b = Button(toolbar, text="Contact-us", width=9)
b.pack(side=LEFT, padx=2, pady=2)

b = Button(toolbar, text="Travelling", width=9)
b.pack(side=LEFT, padx=2, pady=2)



toolbar.pack(side=TOP, fill=X)

o = Label(root,text="Frank Anne",font =("Italic",18,"bold"))
o.pack()
toolbar1 = Frame(root)
b = Button(toolbar1, text="Name",width=9)
b.pack(side=LEFT, padx=2, pady=2)

o = Label(root,text="27",font =("Italic",10,"bold"))
o.pack()

o = Label(root,text="Frankie anne",font =("Italic",10,"bold"))
o.pack(side=TOP, padx=0, pady=0)


toolbar1.pack(side=BOTTOM, fill=X)


toolbar2 = Frame(root)
b = Button(toolbar2, text="Age",width=9)
b.pack(side=LEFT, padx=2, pady=2)
b.pack(side=BOTTOM, padx=2, pady=2)



toolbar2.pack(side=BOTTOM, fill=X)

mainloop()

You can add side=LEFT to your objects and intersparce \\n in with your texts to make new lines. 您可以将side=LEFT添加到对象中,并在文本中插入\\n以创建新行。 I'm a little confused on why you have a toolbar2 with an age button when the age text is part of toolbar 1. I would probably group those together too depending on what you want. 当年龄文本是工具栏1的一部分时,我为什么会带有一个带有年龄按钮的工具栏2感到有些困惑。我也可能根据需要将它们组合在一起。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM