- 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
Tkinter-How to get the current date to display in a tkinter window?
To display the current date in tkinter window, we will use the datetime library.
date = dt.datetime.now()
Steps −
Import the required libraries and create an instance of tkinter frame.
Set the size of the frame using geometry method.
Call datetime.now() and store the value in a variable "date".
Next, create a label to display the date. In the text parameter of the label, pass the date value and format the data as text=f"{date:%A, %B %d, %Y}".
%A – Day of the week, full name
%B – Full month name
%d – Day of the month
%Y – Year with century as a decimal number
Finally, run the mainloop of the application window.
Example −
# Import the libraries from tkinter import * import datetime as dt # Create an instance of tkinter win = Tk() win.title("Display Current Date") win.geometry("700x350") date = dt.datetime.now() # Create Label to display the Date label = Label(win, text=f"{date:%A, %B %d, %Y}", font="Calibri, 20") label.pack(pady=20) win.mainloop()
Output
On execution, it will produce the following output −
- Related Articles
- How to get the current date to display in a Tkinter window?
- How to draw images in the Tkinter window?
- How to display an image/screenshot in a Python Tkinter window without saving it?
- How to show webcam in TkInter Window?
- How to add a margin to a tkinter window?
- How to center a window on the screen in Tkinter?
- How to make a Tkinter window jump to the front?
- How to bind the Enter key to a tkinter window?
- How to make a Tkinter window not resizable?
- How to delete Tkinter widgets from a window?
- Function to close the window in Tkinter
- How to get the current length of the Text in a Tkinter Text widget?
- How to make Tkinter Window appear in the taskbar?
- How to put a Toplevel window in front of the main window in Tkinter?
- How to control automated window resizing in Tkinter?

Advertisements