Google News
logo
Tkinter - Interview Questions
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.
Advertisement