import streamlit as st
import calendar
from PIL import Image
# Function to display the full calendar for a specific month and year
def display_full_calendar(year, month, month_images):
# Display the month and year
st.write(f"### {calendar.month_name[month]} {year}")
# Get the calendar for the month (returns a list of weeks)
month_calendar = calendar.monthcalendar(year, month)
# Days of the week headers
days_of_week = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
# Set the background image for the month
bg_image_url = month_images.get(month, None)
if bg_image_url:
st.markdown(
f"""
""", unsafe_allow_html=True)
# Create the table
table_html = "
"
# Add the days of the week as the header row
table_html += ""
for day in days_of_week:
table_html += f"{day} | "
table_html += "
"
# Add the weeks to the table
for week in month_calendar:
table_html += ""
for i, day in enumerate(week):
if day == 0:
table_html += " | " # Empty cell for days not in the month
else:
# Color weekends (Saturday and Sunday)
if i == 5 or i == 6:
table_html += f"{day} | "
else:
table_html += f"{day} | "
table_html += "
"
table_html += "
"
# Display the formatted calendar as HTML
st.markdown(table_html, unsafe_allow_html=True)
# Streamlit app title
st.title('2025 Calendar Viewer')
# File uploader to upload images
st.subheader('Upload images for each month')
uploaded_files = {}
months = list(calendar.month_name[1:])
for month in months:
uploaded_files[month] = st.file_uploader(f"Upload image for {month}", type=["jpg", "png"])
# Map the uploaded images to each month
month_images = {}
for month, image in uploaded_files.items():
if image is not None:
month_images[calendar.month_name.index(month)] = image
# Get user input for the month (default to 2025)
year = 2025
month = st.slider('Select month:', 1, 12, 1)
# Display the calendar for the selected month of the year 2025
display_full_calendar(year, month, month_images)
# Optionally, display all months in 2025
if st.checkbox('Show all months for 2025'):
for month in range(1, 13):
display_full_calendar(year, month, month_images)