简体   繁体   English

为什么这个按钮没有居中,Tkinter

[英]Why is this Button not centered, Tkinter

I'm attempting to center a button (self.HBu) within my frame. 我试图将按钮(self.HBu)居中放置在框架中。 For some reason when I run this, the button sticks toward the bottom of the frame. 由于某种原因,运行此按钮时,按钮会朝着框架的底部移动。 What am I doing wrong? 我究竟做错了什么?

Snippet: 片段:

    frame = Tk.Frame(self).pack(ipadx=180, ipady=100)

    self.HBu = Tk.Button(frame, text='click', command=self.do_stuff)

    self.HBu.pack()

Are you aware that by default, pack places widgets at the top of a frame? 您是否知道默认情况下,将放置小部件打包在框架的顶部? There is no explanation for it being at the bottom, based on the code you posted. 根据您发布的代码,它的底部没有解释。

Try adding side="left" to your pack statement if you want the button on the left side of your frame. 如果您想要按钮在框架的左侧,请尝试在您的pack语句中添加side="left" If that doesn't work, make sure it's really at the bottom of your frame, and not that it's in the right place in the frame, but that the frame is in the wrong place. 如果这不起作用,请确保它确实位于框架的底部,而不是它在框架中的正确位置,而是框架在错误的位置。

When debugging layout problems, it sometimes helps to set the background of various frames to different colors so you can visualize how things are aligned within each container. 在调试布局问题时,有时可以将各种框架的背景设置为不同的颜色,以便您可以直观地看到每个容器中的对齐方式。

Check the Dock Property of the Button, it may be set to bottom i think. 检查按钮的Dock属性,我认为它可能设置为底部。 r else some where in the coding the align property of the button is modified. 还有一些在编码中修改了按钮的align属性的地方。

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

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