Tkinter: How to make a button center itself? Tkinter: How to make a button center itself? tkinter tkinter

Tkinter: How to make a button center itself?


If this can't resolve your problem

button.pack(side=TOP)

You'll need to use the method

button.grid(row=1,col=0)

the values of row=1,col=0 depend of the position of the other widget in your window

or you can use .place(relx=0.5, rely=0.5, anchor=CENTER)

button.place(relx=0.5, rely=0.5, anchor=CENTER)

Example using .place():

from tkinter import *  # Use this if use python 3.xx#from Tkinter import *   # Use this if use python 2.xxa = Button(text="Center Button")b = Button(text="Top Left Button")c = Button(text="Bottom Right Button")a.place(relx=0.5, rely=0.5, anchor=CENTER)b.place(relx=0.0, rely=0.0, anchor=NW)c.place(relx=1.0, rely=1.0, anchor=SE)mainloop()

tk window