Why is this Button not centered, Tkinter
Asked Answered
N

2

0

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()
Nodule answered 25/2, 2011 at 6:55 Comment(1)
When I run the above code the button sticks to the top of the frame, as expected. Are you sure this is representative of your problem?Pa
P
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.

Pa answered 25/2, 2011 at 12:21 Comment(0)
V
-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.

Veterinary answered 25/2, 2011 at 6:59 Comment(1)
tk widgets don't have a dock or Dock property. Maybe you are thinking of some other toolkit?Pa

© 2022 - 2024 — McMap. All rights reserved.