Computer >> 컴퓨터 >  >> 프로그램 작성 >> Python

Tkinter에서 날짜 선택 캘린더 만들기


Tkinter는 응용 프로그램을 만들고 개발하는 데 널리 사용되는 Python 라이브러리입니다. 응용 프로그램에 여러 기능을 추가하는 데 사용할 수 있는 다양한 방법과 기능을 가지고 있습니다.

Tkcalendar 창에서 GUI 기반 달력을 만드는 데 사용할 수 있는 tkinter 패키지 중 하나이므로 데이터 선택, 달력 응용 프로그램을 통한 이벤트 선택 및 예약 등과 같은 여러 작업을 수행할 수 있습니다.

그러나 이 기사에서는 Tkcalendar 패키지를 사용하여 날짜 선택기 달력을 만드는 방법을 살펴보겠습니다. 그 전에 pip install tkcalendar를 사용하여 로컬 환경에 패키지를 설치해야 합니다. .

설치가 완료되면 tkcalendar의 인스턴스를 만들고 날짜를 가져오는 버튼을 만듭니다.

예시

#Import the libraries
from tkinter import *
from tkcalendar import *

#Create an instance of tkinter frame or window
win= Tk()
win.title("Calendar")
win.geometry("700x600")

cal= Calendar(win, selectmode="day",year= 2021, month=3, day=3)
cal.pack(pady=20)

#Define Function to select the date
def get_date():
   label.config(text=cal.get_date())

#Create a button to pick the date from the calendar
button= Button(win, text= "Select the Date", command= get_date)
button.pack(pady=20)

#Create Label for displaying selected Date
label= Label(win, text="")
label.pack(pady=20)

win.mainloop()

출력

위의 코드를 실행하면 특정 날짜를 선택할 수 있는 달력이 생성됩니다.

Tkinter에서 날짜 선택 캘린더 만들기