How do I position the buttons on a Tkinter window?


To set the position of a button, we use the place method of button widget. The place method takes the x and y coordinates of the button.

Steps −

  • Import the required libraries and create an instance of tkinter frame.

  • Set the size of the frame using win.geometry method.

  • Next, create multiple buttons and name them "Button-1", "Button-2", etc.

  • Set the position of the buttons using the place method by supplying the x and y coordinate values.

  • Finally, run the mainloop of the application window.


# Import the Tkinter library
from tkinter import *
from tkinter import ttk

# Create an instance of Tkinter frame
win = Tk()

# Define the geometry

# Create Buttons in the frame
button = ttk.Button(win, text="Button-1"), y=125)

button = ttk.Button(win, text="Button-2"), y=175)

button = ttk.Button(win, text="Button-3"), y=225)

#Create a Label
Label(win, text="Position the Buttons", font='Consolas 15').pack()



When you execute this code, it will show the following window −

Notice that we have fixed the x variable at 325 in all the three buttons which is why the buttons are aligned. You can alter the (x, y) values in the place method to change the position of the buttons.

Updated on 26-Oct-2021 12:38:26