0

我试图在我的框架内居中一个按钮(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()
4

2 回答 2

2

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.

于 2011-02-25T12:21:31.573 回答
-1

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.

于 2011-02-25T06:59:51.530 回答