- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Setting the position on a button in Tkinter Python?
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 win.geometry("750x250") def close_win(): win.destroy() # Create Buttons in the frame button = ttk.Button(win, text="Click", command=close_win) button.place(x=325, y=125) #Create a Label Label(win, text="Click the Button to Close the Window", font=('Consolas 15')).pack() win.mainloop()
Running the above code will display a window containing a button at the center position of the window.
- Add image on a Python Tkinter button
- How to set the position of a Tkinter window without setting the dimensions?
- Creating a button in tkinter in Python
- How do I position the buttons on a Tkinter window?
- Mouse Position in Python Tkinter
- On/Off Toggle Button Switch in Tkinter
- How to create a Button on a Tkinter Canvas?
- Setting Background color for Tkinter in Python
- Setting Background Position in CSS
- How do you create a Button on a Tkinter Canvas?
- Setting Background Position using CSS
- How to press a button without touching it on Tkinter?
- Add style to Python tkinter button
- Setting the focus to a specific Tkinter entry widget
- Tkinter button commands with lambda in Python