- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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.
Example
# Import the Tkinter library from tkinter import * from tkinter import ttk # Create an instance of Tkinter frame win = Tk() # Define the geometry win.geometry("750x350") # Create Buttons in the frame button = ttk.Button(win, text="Button-1") button.place(x=325, y=125) button = ttk.Button(win, text="Button-2") button.place(x=325, y=175) button = ttk.Button(win, text="Button-3") button.place(x=325, y=225) #Create a Label Label(win, text="Position the Buttons", font='Consolas 15').pack() win.mainloop()
Output
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.
- Related Articles
- How do I close a tkinter window?
- How do I create a popup window using Tkinter?
- How do I create a popup window in Tkinter?
- How do I open a website in a Tkinter window?
- How do I create a popup window using Tkinter Program?
- How do I set a minimum window size in Tkinter?
- How do I handle the window close event in Tkinter?
- How do I get the width and height of a Tkinter window?
- Dynamically Resize Buttons When Resizing a Window using Tkinter
- How do I get rid of the Python Tkinter root window?
- How do I insert a JPEG image into a Python Tkinter window?
- How do I use Window Manager (wm) attributes in Tkinter?
- How do I update images on a Tkinter Canvas?
- How to set the position of a Tkinter window without setting the dimensions?
- Python Tkinter – How to position a topLevel() widget relative to the root window?

Advertisements