简体   繁体   中英

Why is this Button not centered, Tkinter

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()

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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