为什么这个按钮不居中,Tkinter [英] Why is this Button not centered, Tkinter

查看:36
本文介绍了为什么这个按钮不居中,Tkinter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将一个按钮 (self.HBu) 置于我的框架内.出于某种原因,当我运行它时,按钮会粘在框架的底部.我究竟做错了什么?

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?

片段:

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

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

    self.HBu.pack()

推荐答案

您是否知道默认情况下,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.

如果您想要框架左侧的按钮,请尝试将 side="left" 添加到您的包装语句中.如果这不起作用,请确保它确实位于框架的底部,而不是它在框架中的正确位置,而是框架位于错误的位置.

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.

这篇关于为什么这个按钮不居中,Tkinter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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