- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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 to center a Tkinter widget?
Tkinter widgets are customizable by specifying their properties, for example, width, height, position, background color, etc. To position the Tkinters widgets, we can use place() geometry manager, where we will specify the anchor property. It can take (NW, N, NE, W, CENTER, E, SW, S, SE) as the position of the widget.
Example
In this example, we have forced a Label widget to the center of the window by specifying the anchor property.
#Import the required libraries from tkinter import * #Create an instance of Tkinter Frame win = Tk() #Set the geometry win.geometry("700x350") #Set the default color of the window win.config(bg='#4fe3a5') #Create a Label Label(win, text = "Hello World!", font= ('Helvetica 25 bold')).place(relx=.5, rely=.5,anchor= CENTER) win.mainloop()
Output
Running the above code will display a window with a Label widget at the center of the window.
- Related Articles
- How to center a Tkinter widget in a sticky frame?
- How to horizontally center a widget using a grid() in Tkinter?
- How do I center the text in a Tkinter Text widget?
- How to make a Tkinter widget invisible?
- How to remove focus from a Tkinter widget?
- How to update a Python/tkinter label widget?
- How to update a Button widget in Tkinter?
- How to add a column to a Tkinter TreeView widget?
- How to erase everything from a Tkinter text widget?
- How to see if a widget exists in Tkinter?
- How to create hyperlink in a Tkinter Text widget?
- How to highlight text in a tkinter Text widget?
- How to set focus for Tkinter widget?
- How to connect a variable to the Tkinter Entry widget?
- How to attach a Scrollbar to a Text widget in Tkinter?

Advertisements