-
Notifications
You must be signed in to change notification settings - Fork 0
/
To-Do-List.py
42 lines (32 loc) · 940 Bytes
/
To-Do-List.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import streamlit as st
def add_task(task):
file = open("tasks.txt", "a")
file.write(task + "\n")
file.close()
def get_tasks():
try:
with open("tasks.txt", "r") as file:
tasks = file.readlines()
except FileNotFoundError:
with open("tasks.txt", "w") as file:
tasks = []
return tasks
def remove_task(task_to_remove):
tasks = get_tasks()
file = open("tasks.txt", "w")
for task in tasks:
if task.strip() != task_to_remove:
file.write(task)
file.close()
st.title("Simple To-Do List")
task = st.text_input("Enter a task")
if st.button("Add Task"):
add_task(task)
st.success(f"Task '{task}' added.")
st.subheader("Your Tasks")
tasks = get_tasks()
for task in tasks:
task = task.strip()
if st.checkbox(task):
remove_task(task)
st.success(f"Task '{task}' removed.")