- 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 to get the current date to display in a Tkinter window?
To work with the date and time module, Python provides the 'datetime' package. Using 'datetime' package, we can display the date, manipulate the datetime object, and use it to write the additional functionality in an application.
To display the current date in a Tkinter window, we've to first import the datetime module in our environment. Once imported, you can create an instance of its object and display them using the label widget.
Example
Here is an example of how you can show the current date in a Tkinter window.
# Import the required libraries from tkinter import * import datetime as dt # Create an instance of tkinter frame or window win=Tk() # Set the size of the tkinter window win.geometry("700x350") # Create an instance of datetime module date=dt.datetime.now() # Format the date format_date=f"{date:%a, %b %d %Y}" # Display the date in a a label widget label=Label(win, text=format_date, font=("Calibri", 25)) label.pack() win.mainloop()
Output
Running the above code will display the current date in the window.
- Related Articles
- Tkinter-How to get the current date to display in a tkinter window?
- How to get the current date in Java?
- How to display an image/screenshot in a Python Tkinter window without saving it?
- How to get the current date and time in Java?
- How to get the difference between date records and the current date in MySQL?
- How to get current time and date in C++?
- How to get current date and time in Python?
- How to get current date and time in JavaScript?
- How to get the current length of the Text in a Tkinter Text widget?
- How to get the current local date and time in Kotlin?
- How to put a Toplevel window in front of the main window in Tkinter?
- How to get current date/time in seconds in JavaScript?
- How to draw images in the Tkinter window?
- How to center a window on the screen in Tkinter?
- How to make a Tkinter window jump to the front?

Advertisements