날짜 및 시간 모듈을 사용하기 위해 Python은 'datetime' 패키지를 제공합니다. 'DateTime' 사용 패키지를 사용하면 날짜를 표시하고 datetime 개체를 조작하고 응용 프로그램의 추가 기능을 작성하는 데 사용할 수 있습니다.
Tkinter 창에 현재 날짜를 표시하려면 먼저 우리 환경에서 datetime 모듈을 가져와야 합니다. 가져온 후에는 개체의 인스턴스를 만들고 항목 위젯을 사용하여 표시할 수 있습니다.
예시
다음은 Entry 위젯에 현재 날짜를 표시하는 방법의 예입니다.
# 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
entry=Entry(win,width=25, font=("Calibri", 25))
entry.insert(END,format_date)
entry.pack()
win.mainloop() 출력
위의 코드를 실행하면 Entry 위젯에 현재 날짜가 표시됩니다.
