Notepad24b / app.py
flutterbasit's picture
Create app.py
9ba5129 verified
raw
history blame
2.2 kB
import streamlit as st
from datetime import datetime
# Application title
st.set_page_config(page_title="To-Do Notebook", page_icon="πŸ“", layout="centered")
# App header
st.title("πŸ“ To-Do Notebook")
st.subheader("Organize your tasks with ease!")
# App description
st.write("Add your tasks, check them off, and delete them when you're done.")
# Initialize task list in the session state
if "tasks" not in st.session_state:
st.session_state.tasks = []
# Function to add a task
def add_task(task_name, priority, deadline):
if task_name:
st.session_state.tasks.append({
"task": task_name,
"priority": priority,
"deadline": deadline,
"completed": False
})
st.success(f"Task '{task_name}' added!")
# Function to toggle task completion
def toggle_completion(index):
st.session_state.tasks[index]["completed"] = not st.session_state.tasks[index]["completed"]
# Function to delete a task
def delete_task(index):
st.session_state.tasks.pop(index)
st.success("Task deleted!")
# Add task section
with st.expander("βž• Add a New Task"):
task_name = st.text_input("Task Name", placeholder="Enter task here...")
priority = st.selectbox("Priority", ["Low", "Medium", "High"])
deadline = st.date_input("Deadline")
if st.button("Add Task"):
add_task(task_name, priority, deadline)
# Show tasks
if st.session_state.tasks:
st.subheader("πŸ“‹ Your Tasks")
for i, task in enumerate(st.session_state.tasks):
col1, col2, col3 = st.columns([5, 2, 1])
# Display task with checkbox
with col1:
st.checkbox(
f"({task['priority']}) {task['task']} - Due: {task['deadline']}",
value=task["completed"],
on_change=toggle_completion,
args=(i,)
)
# Delete button
with col3:
if st.button("πŸ—‘οΈ", key=f"delete_{i}"):
delete_task(i)
else:
st.info("You have no tasks. Add a new task to get started!")
# Footer
st.write("---")
st.write("✨ Made with ❀️ using Streamlit")
# Run Streamlit locally or deploy
!streamlit run app.py