Calander / app.py
Dearsawan's picture
Update app.py
338b0a4 verified
import streamlit as st
import calendar
# Define images for each month (seasonal backgrounds) - you can change this to URLs of your choice
month_images = {
1: "https://via.placeholder.com/150/0000FF/808080?Text=January", # Placeholder image for January
2: "https://via.placeholder.com/150/FF0000/FFFFFF?Text=February", # Placeholder image for February
3: "https://via.placeholder.com/150/00FF00/FFFFFF?Text=March", # Placeholder image for March
4: "https://via.placeholder.com/150/FFFF00/000000?Text=April", # Placeholder image for April
5: "https://via.placeholder.com/150/FF00FF/FFFFFF?Text=May", # Placeholder image for May
6: "https://via.placeholder.com/150/00FFFF/000000?Text=June", # Placeholder image for June
7: "https://via.placeholder.com/150/FF7F00/FFFFFF?Text=July", # Placeholder image for July
8: "https://via.placeholder.com/150/7FFF00/000000?Text=August", # Placeholder image for August
9: "https://via.placeholder.com/150/8A2BE2/FFFFFF?Text=September", # Placeholder image for September
10: "https://via.placeholder.com/150/FF1493/FFFFFF?Text=October", # Placeholder image for October
11: "https://via.placeholder.com/150/DC143C/FFFFFF?Text=November", # Placeholder image for November
12: "https://via.placeholder.com/150/800080/FFFFFF?Text=December", # Placeholder image for December
}
# Function to display the full calendar for a specific month and year
def display_full_calendar(year, month):
# 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, "")
st.markdown(
f"""
<style>
.calendar {{
background-image: url('{bg_image_url}');
background-size: cover;
background-position: center;
padding: 20px;
border-radius: 10px;
}}
table {{
border-collapse: collapse;
width: 90%;
margin: 10px auto;
background-color: rgba(255, 255, 255, 0.8);
}}
th, td {{
text-align: center;
padding: 8px;
border: 1px solid #ccc;
font-size: 12px;
height: 30px;
}}
th {{
background-color: #f2f2f2;
color: #333;
}}
td {{
background-color: #ffffff;
color: #333;
}}
td.weekend {{
background-color: #ffeb3b; /* Yellow for weekends */
}}
td.empty {{
background-color: rgba(255, 255, 255, 0.3); /* Light for empty cells */
}}
td.highlight {{
background-color: #76d7c4; /* Light teal for highlight */
}}
</style>
""", unsafe_allow_html=True)
# Create the table
table_html = "<div class='calendar'><table>"
# Add the days of the week as the header row
table_html += "<tr>"
for day in days_of_week:
table_html += f"<th>{day}</th>"
table_html += "</tr>"
# Add the weeks to the table
for week in month_calendar:
table_html += "<tr>"
for i, day in enumerate(week):
if day == 0:
table_html += "<td class='empty'></td>" # Empty cell for days not in the month
else:
# Color weekends (Saturday and Sunday)
if i == 5 or i == 6:
table_html += f"<td class='weekend'>{day}</td>"
else:
table_html += f"<td>{day}</td>"
table_html += "</tr>"
table_html += "</table></div>"
# Display the formatted calendar as HTML
st.markdown(table_html, unsafe_allow_html=True)
# Streamlit app title
st.title('2025 Calendar Viewer')
# 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)
# 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)