There's no trick -- the widget is centered in the area allocated to it by default. Simply place a label in a cell without any sticky attributes and it will be centered.

Now, the other question is, how to get the area it is allocated to be centered. That depends on many other factors, such as what other widgets are there, how they are arranged, etc.

Here's a simple example showing a single centered label. It does this by making sure the row and column it is in takes up all extra space. Notice that the label stays centered no matter how big you make the window.

import Tkinter as tk

class Example(tk.Frame):
    def __init__(self, parent):
        tk.Frame.__init__(self, parent)
        label = tk.Label(self, text="This should be centered")
        label.grid(row=1, column=1)
        self.grid_rowconfigure(1, weight=1)
        self.grid_columnconfigure(1, weight=1)

if __name__ == "__main__":
    root = tk.Tk()
    Example(root).grid(sticky="nsew")
    root.grid_rowconfigure(0, weight=1)
    root.grid_columnconfigure(0, weight=1)
    root.mainloop()

You can get a similar effect by giving a weight to all rows and columns except the one with the label.

import Tkinter as tk

class Example(tk.Frame):
    def __init__(self, parent):
        tk.Frame.__init__(self, parent)
        label = tk.Label(self, text="This should be centered")
        label.grid(row=1, column=1)

        self.grid_rowconfigure(0, weight=1)
        self.grid_rowconfigure(2, weight=1)
        self.grid_columnconfigure(0, weight=1)
        self.grid_columnconfigure(2, weight=1)

if __name__ == "__main__":
    root = tk.Tk()
    Example(root).grid(sticky="nsew")
    root.grid_rowconfigure(0, weight=1)
    root.grid_columnconfigure(0, weight=1)

    root.mainloop()
Answer from Bryan Oakley on Stack Overflow
Top answer
1 of 4
25

There's no trick -- the widget is centered in the area allocated to it by default. Simply place a label in a cell without any sticky attributes and it will be centered.

Now, the other question is, how to get the area it is allocated to be centered. That depends on many other factors, such as what other widgets are there, how they are arranged, etc.

Here's a simple example showing a single centered label. It does this by making sure the row and column it is in takes up all extra space. Notice that the label stays centered no matter how big you make the window.

import Tkinter as tk

class Example(tk.Frame):
    def __init__(self, parent):
        tk.Frame.__init__(self, parent)
        label = tk.Label(self, text="This should be centered")
        label.grid(row=1, column=1)
        self.grid_rowconfigure(1, weight=1)
        self.grid_columnconfigure(1, weight=1)

if __name__ == "__main__":
    root = tk.Tk()
    Example(root).grid(sticky="nsew")
    root.grid_rowconfigure(0, weight=1)
    root.grid_columnconfigure(0, weight=1)
    root.mainloop()

You can get a similar effect by giving a weight to all rows and columns except the one with the label.

import Tkinter as tk

class Example(tk.Frame):
    def __init__(self, parent):
        tk.Frame.__init__(self, parent)
        label = tk.Label(self, text="This should be centered")
        label.grid(row=1, column=1)

        self.grid_rowconfigure(0, weight=1)
        self.grid_rowconfigure(2, weight=1)
        self.grid_columnconfigure(0, weight=1)
        self.grid_columnconfigure(2, weight=1)

if __name__ == "__main__":
    root = tk.Tk()
    Example(root).grid(sticky="nsew")
    root.grid_rowconfigure(0, weight=1)
    root.grid_columnconfigure(0, weight=1)

    root.mainloop()
2 of 4
8

There is nothing special required. A widget will be in the middle of it's parent automatically. What is required to to tell the parent to fill all available space.

from tkinter import *
root = Tk()
root.geometry("500x500+0+0")
frmMain = Frame(root,bg="blue")

startbutton = Button(frmMain, text="Start",height=1,width=4)
startbutton.grid()

#Configure the row/col of our frame and root window to be resizable and fill all available space
frmMain.grid(row=0, column=0, sticky="NESW")
frmMain.grid_rowconfigure(0, weight=1)
frmMain.grid_columnconfigure(0, weight=1)
root.grid_rowconfigure(0, weight=1)
root.grid_columnconfigure(0, weight=1)

root.mainloop()

This uses grid rather than pack to place the widgets and the grid is configured to fill the entire size of the window. The button will appear in the centre regardless of the size of the window.

๐ŸŒ
Python Forum
python-forum.io โ€บ thread-40023.html
Centering and adding a push button to a grid window, TKinter
This May be really simple, but I'm not finding enough details to help as I'm just learning TKinter. I have a simple grid sourced by a Python list, and I'm trying to center it regardless of window size, and add single push button at bottom of the win...
๐ŸŒ
15. The Menu widget
anzeljg.github.io โ€บ rin2 โ€บ book2 โ€บ 2405 โ€บ docs โ€บ tkinter โ€บ grid.html
4.1. The .grid() method
Table 1. Arguments of the .grid() geometry manager ยท If you do not provide a sticky attribute, the default behavior is to center the widget in the cell.
๐ŸŒ
Python Tutorial
pythontutorial.net โ€บ home โ€บ tkinter tutorial โ€บ tkinter grid
Tkinter Grid Geometry Manager - Python Tutorial
April 4, 2025 - EW stretches the widget horizontally. However, it leaves the widget centered vertically: To add paddings between cells of a grid, you use the padx and pady options.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ how-to-horizontally-center-a-widget-using-a-grid-in-tkinter
How to horizontally center a widget using a grid() in Tkinter?
By default, with sticky='', widget is centered in its cell. sticky may be the string concatenation of zero or more of N, E, S, W, NE, NW, SE, and SW, compass directions indicating the sides and corners of the cell to which widget sticks.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ horizontally-center-a-widget-using-tkinter
Horizontally Center a Widget using Tkinter - GeeksforGeeks
July 23, 2025 - Horizontally centering a widget in Tkintercan be achieved using the pack, grid, or place geometry managers, each providing different levels of control and flexibility. The method you choose depends on the specific requirements and complexity of your user interface.
๐ŸŒ
Python GUIs
pythonguis.com โ€บ tutorials โ€บ getting started with tkinter โ€บ using the grid geometry manager in tkinter
Using the Grid Geometry Manager in Tkinter
October 9, 2022 - It can also be a combination of them NW, NE, SW, or SE. If you use W+E+N+S, then the widget will fill the cell. The default behavior is to center the widget within the cell. The following is just a quick example of how to lay out a window using the grid geometry manager in Tkinter.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ how-to-center-a-tkinter-widget-in-a-sticky-frame
How to center a Tkinter widget in a sticky frame?
To center a widget in a sticky frame, we need to configure both the window and frame to be expandable using grid_rowconfigure() and grid_columnconfigure() with weight=1. # Import the required library from tkinter import * # Create an instance ...
Find elsewhere
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ tkinter gui centering?
r/learnpython on Reddit: Tkinter GUI Centering?
February 6, 2024 -

Iโ€™ve coded a wordle GUI using Tkinter. I wonโ€™t include all the code as itโ€™s ~600 lines, but the main problem revolves around the following code (sorry, idk how to make it an actual code box in Reddit):

widget = Label(root, text = โ€˜ โ€˜, font = (โ€˜Arielโ€™, 25)) widget.grid(column = 4, row = 4)

This will make my label, set the parameters, and then align it with the GUI grid.

It all works great except for one thing - the text box displaying โ€œThe word was โ€œ_____โ€!โ€ pushes all the other widgets to the side. I KNOW this is because Iโ€™m using button.grid() to set the locations of all of the buttons, and when the text is finally updated in that text box (changes from โ€˜ โ€˜ to the above text), it makes the width much larger than the other center widgets.

Is there a way within Tkinter to get it to โ€œignoreโ€ the other widgets so it can be whatever width it wants to be without pushing the other widgets to the edges?

๐ŸŒ
ActiveState
activestate.com โ€บ home โ€บ resources โ€บ quick read โ€บ how to position widgets in tkinter
How to Position Widgets in Tkinter - with Grid, Place or Pack - ActiveState
January 24, 2024 - Tkinter has three built-in layout managers that use geometric methods to position widgets in an application frame: pack() organizes widgets in horizontal and vertical boxes that are limited to left, right, top, bottom positions. Each box is offset and relative to each other. place() places widgets in a two dimensional grid using x and y absolute coordinates.
๐ŸŒ
Tkinter
tkinter.com โ€บ center-widgets-with-place-python-tkinter-gui-tutorial-191
Center Widgets With Place โ€“ Python Tkinter GUI Tutorial 191 โ€“ TKinter.com
September 14, 2021 - from tkinter import * root = Tk() root.title('Codemy.com - Center A Thing With Place') root.iconbitmap('c:/gui/codemy.ico') root.geometry("500x500") button_1 = Button(root, text="Button 1", font=("Helvetica", 32)) button_2 = Button(root, text="Button 2", font=("Helvetica", 32)) button_1.grid(column=0, row=0) button_2.grid(column=1, row=0) my_button = Button(root, text="Click Me", font=("Helvetica, 32")) my_button.place(relx=0.5, rely=0.5, anchor=CENTER) #my_button.place(x=100, y=50) root.mainloop()
๐ŸŒ
TkDocs
tkdocs.com โ€บ tutorial โ€บ grid.html
TkDocs Tutorial - The Grid Geometry Manager
For example, a value of n (north) ... on the bottom; the widget will still be centered horizontally. A value of nw (north-west) means the widget will be stuck to the top left corner, with extra space on the bottom and right. In Tkinter, you can also specify this as a list or tuple ...
๐ŸŒ
CustomTkinter
customtkinter.tomschimansky.com โ€บ beginner โ€บ 1. grid system
1. Grid System | CustomTkinter
The grid splits a window or frame into columns and rows, which collapse when they are empty, but adapt to the size of the widgets placed inside them. If you want to center the button in the last example, you would have to give the first column a weight other than zero, so that it does not collapse to the size of the button anymore (use grid_rowconfigure() for rows):
๐ŸŒ
Python
mail.python.org โ€บ pipermail โ€บ tkinter-discuss โ€บ 2015-June โ€บ 003748.html
[Tkinter-discuss] Centering grid inside a frame
July 3, 2015 - With a non-zero weight, and with the non-empty rows/columns with a default weight of zero, the empty rows and columns will be given all extra room, effectively centering the other widgets. from Tkinter import * tk = Tk() Button(tk, text="button1").grid(row=1, column=1, sticky=NSEW) Button(tk, text="button2").grid(row=1, column=2, sticky=NSEW) Button(tk, text="button3").grid(row=2, column=1, sticky=NSEW) Button(tk, text="button4").grid(row=2, column=2, sticky=NSEW) tk.grid_rowconfigure(0, weight=1) tk.grid_rowconfigure(3, weight=1) tk.grid_columnconfigure(0, weight=1) tk.grid_columnconfigure(3, weight=1) tk.mainloop() On Thu, Jun 25, 2015 at 5:17 AM, Vasilis Vlachoudis < Vasilis.Vlachoudis at cern.ch> wrote: > Hi all, > > I want to centre a grid layout (with fixed size) inside a frame > e.g.
๐ŸŒ
DaniWeb
daniweb.com โ€บ programming โ€บ software-development โ€บ threads โ€บ 424169 โ€บ tkinter-center-a-grid-of-buttons
python - Tkinter - center a grid of buttons | DaniWeb
May 25, 2012 - Using place with absolute coordinates makes centering hard. A simpler, robust pattern is: Create your button grid inside a dedicated container Frame.
๐ŸŒ
Python GUIs
pythonguis.com โ€บ faq โ€บ when to use pack, place or grid in tkinter
Tkinter Pack vs Grid vs Place โ€” Which Layout Manager Should You Use?
September 18, 2019 - If you use 'w'+'e'+'n'+'s', then the widget will fill up the 'cell'. Default is to center the widget within the 'cell'. Below is the code for the photo editor using Tkinter and the grid layout manager.
๐ŸŒ
Dafarry
dafarry.github.io โ€บ tkinterbook โ€บ grid.htm
The Tkinter Grid Geometry Manager
For example, W (west) means that the widget should be aligned to the left cell border. W+E means that the widget should be stretched horizontally to fill the whole cell. W+E+N+S means that the widget should be expanded in both directions. Default is to center the widget in the cell. grid_bbox(column=None, row=None, col2=None, row2=None) [#]
๐ŸŒ
YouTube
youtube.com โ€บ watch
Center Widgets With Place() - Python Tkinter GUI Tutorial 191 - YouTube
In this video I'll show you how to center a widget using the place method with Tkinter and Python.Place() is similar to pack() and grid() but allows you to p...
Published ย  September 14, 2021
๐ŸŒ
Tutorialspoint
tutorialspoint.com โ€บ python โ€บ tk_grid.htm
Tkinter grid() Method
By default, with sticky='', widget is centered in its cell. sticky may be the string concatenation of zero or more of N, E, S, W, NE, NW, SE, and SW, compass directions indicating the sides and corners of the cell to which widget sticks.
Top answer
1 of 2
7

The problem is that none of your columns have any weight. It is the weight attribute that decides what columns (and rows) get any extra space. Since none of your columns have a non-zero weight, none of the extra space is allocated to them, so they stay as small as they can be.

As a rule of thumb, you should always give at least one row and one column in a frame a non-zero weight. In your case, giving row 0 and column 0 a weight of 1 for all of the frames seems to work:

self.root.grid_columnconfigure(0, weight=1)
self.root.grid_rowconfigure(0, weight=1)
self.contentFrame.grid_columnconfigure(0, weight=1)
self.contentFrame.grid_rowconfigure(0, weight=1)
self.topBar.grid_columnconfigure(0, weight=1)
self.topBar.grid_rowconfigure(0, weight=1)
2 of 2
1

by using 'how to make tkinter grid expand' in google i came across the problem.

quote from Bryan Oakley

Rows and columns have "weight" which describes how they grow or shrink to fill extra space >in the master. By default a row or column has a weight of zero, which means you've told the >label to fill the column but you haven't told the column to fill the master frame.

To fix this, give the column a weight.

class Test():
    def __init__(self,root):
        self.root = root
        self.root.columnconfigure(0, weight=1)
        self.root.config(bg='green')
        self.message = 'test message'

        self.contentFrame = Frame(self.root)
        self.contentFrame.config(background='black',borderwidth=5,relief ='sunken')
        self.contentFrame.grid(row=0, column=0, sticky='news')
        self.contentFrame.columnconfigure(0, weight=1)

        self.topBar = Frame(self.contentFrame, border=2, relief=RAISED)
        self.topBar.grid(row=0, column=0, columnspan=23,sticky=W+E)
        self.topBar.config(background='blue')
        self.topBar.columnconfigure(0, weight=1)

        self.newGameButton = Button(self.topBar, text="New Game")
        self.newGameButton.grid(row=0, column=0)
        self.newGameButton.config(background='red')

        self.messageBox = Label(self.topBar, text=self.message, height=2)
        self.messageBox.grid(row=1, column=0, columnspan=1,sticky=W+E)
        self.messageBox.config(background='yellow')

Test(root)