为什么这个按钮不居中,Tkinter
我正在尝试将按钮(self.HBu)置于框架内的中心。由于某种原因,当我运行它时,按钮粘在框架的底部。我做错了什么?
片段:
frame = Tk.Frame(self).pack(ipadx=180, ipady=100)
self.HBu = Tk.Button(frame, text='click', command=self.do_stuff)
self.HBu.pack()
I'm attempting to center a button (self.HBu) within my frame. 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()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否知道默认情况下,pack 将小部件放置在框架的顶部?根据您发布的代码,没有任何解释说明它位于底部。
如果您希望按钮位于框架的左侧,请尝试将
side="left"
添加到您的 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. 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.
检查按钮的 Dock 属性,我认为它可能设置为底部。 r 在编码中的其他地方,按钮的对齐属性被修改。
Check the Dock Property of the Button, it may be set to bottom i think. r else some where in the coding the align property of the button is modified.