Repository navigation
Expand file tree
/
Copy pathapp.py
More file actions
51 lines (43 loc) · 1.61 KB
/
Copy pathapp.py
File metadata and controls
51 lines (43 loc) · 1.61 KB
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
43
44
45
46
47
48
49
50
51
import tkinter as tk
from tkinter import messagebox
import sqlite3
# Initialize the main window
root = tk.Tk()
root.title("Sticky Notes")
root.geometry("400x400")
# Connect to SQLite database
conn = sqlite3.connect('notes.db')
c = conn.cursor()
c.execute('''CREATE TABLE IF NOT EXISTS notes (title TEXT, content TEXT)''')
conn.commit()
# Functions
def save_note():
title = title_entry.get()
content = content_text.get("1.0", tk.END)
if title and content.strip():
c.execute("INSERT INTO notes (title, content) VALUES (?, ?)", (title, content))
conn.commit()
messagebox.showinfo("Success", "Note saved successfully!")
title_entry.delete(0, tk.END)
content_text.delete("1.0", tk.END)
else:
messagebox.showwarning("Input Error", "Please enter both title and content.")
def view_notes():
c.execute("SELECT title, content FROM notes")
notes = c.fetchall()
notes_window = tk.Toplevel(root)
notes_window.title("Saved Notes")
for idx, (title, content) in enumerate(notes, start=1):
tk.Label(notes_window, text=f"{idx}. {title}").pack()
tk.Label(notes_window, text=content).pack()
tk.Label(notes_window, text="-"*40).pack()
# UI Elements
tk.Label(root, text="Title:").pack()
title_entry = tk.Entry(root, width=50)
title_entry.pack()
tk.Label(root, text="Content:").pack()
content_text = tk.Text(root, height=10, width=50)
content_text.pack()
tk.Button(root, text="Save Note", command=save_note).pack(pady=5)
tk.Button(root, text="View Notes", command=view_notes).pack(pady=5)
root.mainloop()