본문 바로가기
Programming/Python

파이썬으로 달력 만들어보기! - 심코딩

by 심코딩 2022. 10. 5.

오늘은 파이썬 GUI에서 가장 기본적인 tkinter를 통해 달력을 만들어 보겠습니다, 달력을 만든 후 오늘 날짜에 하이라이트가 되도록 해보겠습니다.

 

라이브러리 설치

 

tkinter를 이용하기 위해서는 두가지 라이브러리를 설치를 하여야 합니다. 바로 tkinter와 tkcalendar 라고 하는 라이브러리들 입니다. 설치방법은 cmd를 여신다음 아래와 같이 각각 입력해주시면 되십니다.

 

pip install tkinter
pip install tkcalendar

tkcalendar를 통해 달력을 만들기

 

from tkinter import *
from tkcalendar import *
import datetime

today_time = datetime.date.today()

root = Tk()
root.title("Calendar")
root.geometry("600x400")

cal = Calendar(root, selectmode="day", year=today_time.year, month=today_time.month, day=today_time.day)
cal.pack(fill = "both", expand = True)

root.mainloop()

 

datetime 모듈을 이용하여 오늘 현재의 날짜를 받아 올 수 있으며, Calendar()를 이용하여 오늘 날짜를 넣어주시면 되십니다. 이렇게 실행을 하시면 아래와 같이 달력이 잘 뜨는 것을 볼 수 있습니다.

 

 

댓글