Setting the position on a button in Tkinter Python?

PythonTkinterServer Side ProgrammingProgramming

There are certain ways through which Tkinter widgets can be positioned inside a window. Tkinter Geometry manager has three methods, pack(), place() and grid(), through which we can set the position of the widget in an application window. Each of these ways has its own limitations and uses. To set the position of a button on a Tkinter application window, we can prefer to use the place(x-coordinates, y-coordinates) method over all the other methods. It takes the values of x and y coordinates which are required to define the position of a widget.


The sample code contains a button widget that uses the place(x, y) method to position the button in the window.

# Import the Tkinter library
from tkinter import *
from tkinter import ttk
# Create an instance of Tkinter frame
win = Tk()
# Define the geometry
def close_win():
# Create Buttons in the frame
button = ttk.Button(win, text="Click", command=close_win), y=125)
#Create a Label
Label(win, text="Click the Button to Close the Window", font=('Consolas 15')).pack()


Running the above code will display a window containing a button at the center position of the window.

Updated on 22-Apr-2021 07:47:39