발전을 위한 기록

[Python] 파이썬으로 달력 만들기2 - <색상 바꾸기> 본문

프로그래밍/파이썬

[Python] 파이썬으로 달력 만들기2 - <색상 바꾸기>

릴릴2 2024. 1. 27. 18:01

이전 포스팅에서 만든 달력의 색상을 바꾸는 코드입니다!

기본 달력을 만드는 방법은 아래 게시물을 참고 해주세요!

https://riwltnchgo.tistory.com/112

 

[Python] 파이썬으로 달력 만들기1 - <GUI>

파이썬을 사용하여 달력을 표시하는 GUI 프로그램 입니다. 이 예제에서는 tkinter 라이브러리와 tkcalendar 모듈을 사용합니다. 1. 필요한 모듈 설치하기 tkcalendar 모듈을 설치해야 합니다. pip install tkca

riwltnchgo.tistory.com

 


❗ 모듈 설치가 필요합니다

Tkinter용 달력 위젯을 제공하는 별도의 모듈입니다.

pip install tkcalendar

코드

import tkinter as tk
from tkcalendar import Calendar

def on_date_select(event):
    selected_date = cal.selection_get()
    print(f"Selected Date is: {selected_date}")

root = tk.Tk()
root.title("한국 달력")

# 사용자 정의 폰트 설정
custom_font = ('Arial', 12, 'bold')  # 원하는 폰트 및 크기로 변경 가능

# 캘린더 위젯을 생성하고, 여러 색상 및 스타일 옵션을 추가합니다.
cal = Calendar(root, 
               selectmode='day',
               font = custom_font,
               
               # 캘린더 배경색 (기본: 'white')
               background='white',
               
               # 텍스트 색상 (기본: 'black')
               foreground='black',
               
               # 테두리 색상 (기본: 'gray')
               bordercolor='gray',
               
               # 달력 헤더 배경색 (월, 연도 표시 부분) (기본: 'lightgray')
               headersbackground='#6096B4',
               
               # 달력 헤더 텍스트 색상 (기본: 'black')
               headersforeground='white',
               
               # 선택한 날짜의 배경색 (기본: 'blue')
               selectbackground='#27374D',
               
               # 선택한 날짜의 텍스트 색상 (기본: 'white')
               selectforeground='white',
               
               # 일반 날짜의 배경색 (기본: 'white')
               normalbackground='white',
               
               # 일반 날짜의 텍스트 색상 (기본: 'black')
               normalforeground='black',
               
               # 주말 날짜의 배경색 (기본: 없음)
               weekendbackground='#BDCDD6',
               
               # 주말 날짜의 텍스트 색상 (기본: 'black')
               weekendforeground='black',
               
               # 다른 달의 날짜 텍스트 색상 (기본: 'gray50')
               othermonthforeground='gray50',
               
               # 다른 달의 날짜 배경색 (기본: 'white')
               othermonthbackground='white',
               
               # 다른 달의 주말 텍스트 색상 (기본: 'gray50')
               othermonthweforeground='gray50',
               
               # 다른 달의 주말 배경색 (기본: 'light blue')
               othermonthwebackground='#EEE9DA')

cal.pack(pady=20)

root.mainloop()

변경 전

 

변경 후

 

728x90