Skip to content

Commit 8546cdf

Browse files
I have created a ToDoList Application using tkinter library in python
1 parent 557c7f8 commit 8546cdf

File tree

2 files changed

+210
-0
lines changed

2 files changed

+210
-0
lines changed

ToDoAppTkInter/To_Do_AppTkInter.py

Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
import tkinter as tk
2+
from tkinter import messagebox, ttk
3+
from tkcalendar import DateEntry
4+
import sqlite3
5+
6+
class TodoApp:
7+
def __init__(self, root):
8+
self.root = root
9+
self.root.title("Advanced To-Do List")
10+
self.root.geometry("900x600")
11+
12+
# Initialize attributes
13+
self.is_dark_theme = True # Start with dark theme
14+
15+
# Create main frame and sidebar frame
16+
self.main_frame = tk.Frame(self.root, bg="#2E2E2E")
17+
self.main_frame.pack(side=tk.RIGHT, fill=tk.BOTH, expand=True)
18+
19+
self.sidebar_frame = tk.Frame(self.root, width=200, bg="#3A3A3A")
20+
self.sidebar_frame.pack(side=tk.LEFT, fill=tk.Y)
21+
22+
self.create_widgets()
23+
self.create_database()
24+
self.apply_theme() # Apply theme after frames are created
25+
self.create_sidebar()
26+
self.load_tasks()
27+
28+
def create_sidebar(self):
29+
"""Create the sidebar with navigation options."""
30+
tk.Label(self.sidebar_frame, text="Menu", font=("Helvetica", 16), bg="#3A3A3A", fg="#FFFFFF").pack(pady=10)
31+
32+
# Create the "View All Tasks" button
33+
self.view_all_button = tk.Button(
34+
self.sidebar_frame,
35+
text="View All Tasks",
36+
command=self.load_tasks,
37+
bg="#5A5A5A",
38+
fg="#FFFFFF",
39+
relief="flat"
40+
)
41+
self.view_all_button.pack(pady=5, padx=10, fill=tk.X)
42+
43+
# Create other buttons like "View Completed Tasks", "View Pending Tasks", etc.
44+
self.view_completed_button = tk.Button(
45+
self.sidebar_frame,
46+
text="View Completed Tasks",
47+
command=self.load_completed_tasks,
48+
bg="#5A5A5A",
49+
fg="#FFFFFF",
50+
relief="flat"
51+
)
52+
self.view_completed_button.pack(pady=5, padx=10, fill=tk.X)
53+
54+
self.view_pending_button = tk.Button(
55+
self.sidebar_frame,
56+
text="View Pending Tasks",
57+
command=self.load_pending_tasks,
58+
bg="#5A5A5A",
59+
fg="#FFFFFF",
60+
relief="flat"
61+
)
62+
self.view_pending_button.pack(pady=5, padx=10, fill=tk.X)
63+
64+
# Search entry and label
65+
tk.Label(self.sidebar_frame, text="Search:", bg="#3A3A3A", fg="#FFFFFF").pack(pady=5)
66+
self.search_entry = tk.Entry(self.sidebar_frame, bg="#4B4B4B", fg="#FFFFFF", relief="flat")
67+
self.search_entry.pack(pady=5, padx=10, fill=tk.X)
68+
self.search_entry.bind('<KeyRelease>', self.search_tasks)
69+
70+
# Toggle theme button
71+
self.theme_button = tk.Button(
72+
self.sidebar_frame,
73+
text="Toggle Theme",
74+
command=self.toggle_theme,
75+
bg="#5A5A5A",
76+
fg="#FFFFFF",
77+
relief="flat"
78+
)
79+
self.theme_button.pack(pady=5, padx=10, fill=tk.X)
80+
81+
def apply_theme(self):
82+
"""Apply the current theme to the application."""
83+
if self.is_dark_theme:
84+
bg_color = "#2E2E2E"
85+
fg_color = "#FFFFFF"
86+
button_bg = "#5A5A5A"
87+
entry_bg = "#4B4B4B"
88+
else:
89+
bg_color = "#F0F0F0"
90+
fg_color = "#000000"
91+
button_bg = "#D0D0D0"
92+
entry_bg = "#FFFFFF"
93+
94+
self.root.configure(bg=bg_color)
95+
self.main_frame.configure(bg=bg_color)
96+
self.sidebar_frame.configure(bg="#3A3A3A" if self.is_dark_theme else "#F0F0F0")
97+
98+
# Update the colors of sidebar elements
99+
for widget in self.sidebar_frame.winfo_children():
100+
if isinstance(widget, tk.Button):
101+
widget.configure(bg=button_bg, fg=fg_color)
102+
elif isinstance(widget, tk.Entry):
103+
widget.configure(bg=entry_bg, fg=fg_color)
104+
105+
def toggle_theme(self):
106+
"""Toggle between light and dark themes."""
107+
self.is_dark_theme = not self.is_dark_theme
108+
self.apply_theme()
109+
110+
def create_database(self):
111+
"""Create the tasks table if it doesn't exist."""
112+
self.conn = sqlite3.connect("tasks.db")
113+
with self.conn:
114+
self.conn.execute("""
115+
CREATE TABLE IF NOT EXISTS tasks (
116+
id INTEGER PRIMARY KEY,
117+
task TEXT NOT NULL,
118+
category TEXT,
119+
due_date TEXT,
120+
priority TEXT,
121+
completed INTEGER DEFAULT 0
122+
)
123+
""")
124+
125+
def create_widgets(self):
126+
"""Create the main content area widgets."""
127+
frame = tk.Frame(self.main_frame, bg="#2E2E2E" if self.is_dark_theme else "#FFFFFF", padx=10, pady=10)
128+
frame.pack(pady=20, padx=20, fill=tk.BOTH, expand=True)
129+
130+
# Task entry
131+
tk.Label(frame, text="Task:", font=("Helvetica", 12), bg=frame["bg"], fg="#FFFFFF" if self.is_dark_theme else "#000000").grid(row=0, column=0, sticky="w", pady=5)
132+
self.task_entry = tk.Entry(frame, width=50, bg="#4B4B4B", fg="#FFFFFF", relief="flat")
133+
self.task_entry.grid(row=0, column=1, sticky="ew", padx=5, pady=5)
134+
135+
# Category entry
136+
tk.Label(frame, text="Category:", font=("Helvetica", 12), bg=frame["bg"], fg="#FFFFFF" if self.is_dark_theme else "#000000").grid(row=1, column=0, sticky="w", pady=5)
137+
self.category_entry = tk.Entry(frame, width=50, bg="#4B4B4B", fg="#FFFFFF", relief="flat")
138+
self.category_entry.grid(row=1, column=1, sticky="ew", padx=5, pady=5)
139+
140+
# Due date entry
141+
tk.Label(frame, text="Due Date:", font=("Helvetica", 12), bg=frame["bg"], fg="#FFFFFF" if self.is_dark_theme else "#000000").grid(row=2, column=0, sticky="w", pady=5)
142+
self.due_date_entry = DateEntry(frame, width=20, date_pattern='yyyy-mm-dd', background='#4B4B4B', foreground='white', relief="flat")
143+
self.due_date_entry.grid(row=2, column=1, sticky="w", padx=5, pady=5)
144+
145+
# Priority menu
146+
tk.Label(frame, text="Priority:", font=("Helvetica", 12), bg=frame["bg"], fg="#FFFFFF" if self.is_dark_theme else "#000000").grid(row=3, column=0, sticky="w", pady=5)
147+
self.priority_var = tk.StringVar(value="Medium")
148+
self.priority_menu = ttk.Combobox(frame, textvariable=self.priority_var, values=["High", "Medium", "Low"], state="readonly")
149+
self.priority_menu.grid(row=3, column=1, sticky="w", padx=5, pady=5)
150+
151+
# Add task button
152+
self.add_task_button = tk.Button(frame, text="Add Task", command=self.add_task, bg="#5A5A5A", fg="#FFFFFF", relief="flat")
153+
self.add_task_button.grid(row=4, column=1, sticky="e", pady=10)
154+
155+
# Listbox for tasks
156+
self.task_listbox = tk.Listbox(self.main_frame, font=("Helvetica", 10), bg="#2E2E2E", fg="#FFFFFF", height=15, relief="flat")
157+
self.task_listbox.pack(pady=10, padx=20, fill=tk.BOTH, expand=True)
158+
159+
def load_tasks(self):
160+
"""Load all tasks from the database."""
161+
self.task_listbox.delete(0, tk.END)
162+
cursor = self.conn.cursor()
163+
cursor.execute("SELECT * FROM tasks WHERE completed=0")
164+
for row in cursor.fetchall():
165+
self.task_listbox.insert(tk.END, f"{row[1]} | {row[2]} | Due: {row[3]} | Priority: {row[4]}")
166+
167+
def load_completed_tasks(self):
168+
"""Load completed tasks."""
169+
self.task_listbox.delete(0, tk.END)
170+
cursor = self.conn.cursor()
171+
cursor.execute("SELECT * FROM tasks WHERE completed=1")
172+
for row in cursor.fetchall():
173+
self.task_listbox.insert(tk.END, f"{row[1]} | {row[2]} | Due: {row[3]} | Priority: {row[4]}")
174+
175+
def load_pending_tasks(self):
176+
"""Load pending tasks."""
177+
self.load_tasks()
178+
179+
def add_task(self):
180+
"""Add a new task."""
181+
task = self.task_entry.get()
182+
category = self.category_entry.get()
183+
due_date = self.due_date_entry.get()
184+
priority = self.priority_var.get()
185+
186+
if task and category and due_date:
187+
with self.conn:
188+
self.conn.execute("INSERT INTO tasks (task, category, due_date, priority) VALUES (?, ?, ?, ?)",
189+
(task, category, due_date, priority))
190+
self.load_tasks()
191+
self.task_entry.delete(0, tk.END)
192+
self.category_entry.delete(0, tk.END)
193+
else:
194+
messagebox.showwarning("Input Error", "Please fill all fields.")
195+
196+
def search_tasks(self, event):
197+
"""Search tasks based on input."""
198+
query = self.search_entry.get().lower()
199+
self.task_listbox.delete(0, tk.END)
200+
cursor = self.conn.cursor()
201+
cursor.execute("SELECT * FROM tasks WHERE completed=0")
202+
for row in cursor.fetchall():
203+
task_str = f"{row[1]} | {row[2]} | Due: {row[3]} | Priority: {row[4]}"
204+
if query in task_str.lower():
205+
self.task_listbox.insert(tk.END, task_str)
206+
207+
if __name__ == "__main__":
208+
root = tk.Tk()
209+
app = TodoApp(root)
210+
root.mainloop()

tasks.db

8 KB
Binary file not shown.

0 commit comments

Comments
 (0)