Skip to content

Commit ac7faad

Browse files
authored
Merge pull request #596 from SwarajBaral/main
Sticky Notes
2 parents 5fe37b8 + 418272b commit ac7faad

File tree

4 files changed

+165
-0
lines changed

4 files changed

+165
-0
lines changed

sticky_notes/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Sticky Notes
2+
3+
A gui based notes keeping app that is designed to be handy, fast and efficient for small notes that you take throughout the day. It uses python's in-built gui library tkinter.
4+
5+
## Usage
6+
7+
- Copy the contents of the folder into your desired location
8+
- Run the command `pip install -r requirements.txt`
9+
- Execute the script `python sticky_notes.py`
10+
11+
### Getting started
12+
This application is intuitive and easy to use. The layout consists of a list view and 4 buttons :-
13+
- Add a note - Adds the content of the text box as a new note
14+
- Delete a note - Deletes the highlighted note
15+
- Check item - Checks the selected item, i.e., marks it as done
16+
- Uncheck item - Unchecks the selected item.
17+
18+
## Authors
19+
20+
- [@SwarajBaral](https://www.github.com/SwarajBaral)
21+

sticky_notes/add.png

4.54 KB
Loading

sticky_notes/favicon.ico

1.12 KB
Binary file not shown.

sticky_notes/sticky_notes.py

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
from tkinter import Tk, Label, Frame, Entry, Button, Listbox, Scrollbar, TclError
2+
from tkinter.font import Font
3+
from tkinter import END, TOP, BOTTOM, ANCHOR, LEFT, BOTH, RIGHT, FLAT
4+
import ctypes
5+
6+
ctypes.windll.shcore.SetProcessDpiAwareness(True)
7+
8+
# Error handler in GUI
9+
10+
11+
def err(msg):
12+
error.config(text=f"Error: {msg}", fg="red", font=('Sans Serif', 18))
13+
error.pack(pady=20)
14+
15+
# Tkinter button functions
16+
17+
18+
def add_note():
19+
if len(notes_entry.get()) == 0:
20+
err("Please enter a note first.")
21+
else:
22+
error.pack_forget()
23+
start_msg.pack_forget()
24+
notes_list.insert(
25+
END, f"{notes_list.size() + 1}. " + notes_entry.get())
26+
notes_entry.delete(0, END)
27+
notes_list.see("end")
28+
29+
30+
def delete_note():
31+
try:
32+
selected = notes_list.get(notes_list.curselection())
33+
if len(selected) == 0:
34+
error.config(text="Error: Please select a note first to delete.")
35+
error.pack()
36+
else:
37+
notes_list.delete(ANCHOR)
38+
if notes_list.size() == 0:
39+
start_msg.pack(before=notes_list)
40+
error.pack_forget()
41+
except TclError:
42+
err("Select a note to delete")
43+
44+
45+
def check_note():
46+
try:
47+
notes_list.itemconfig(
48+
notes_list.curselection(),
49+
fg="mediumseagreen",
50+
)
51+
notes_list.selection_clear(0, END)
52+
error.pack_forget()
53+
except TclError:
54+
err("Please select a note first.")
55+
56+
57+
def uncheck_note():
58+
try:
59+
notes_list.itemconfig(
60+
notes_list.curselection(),
61+
fg="black",
62+
)
63+
notes_list.selection_clear(0, END)
64+
error.pack_forget()
65+
except TclError:
66+
err("Please select checked note first.")
67+
68+
69+
# Main window
70+
root = Tk()
71+
root.title('Python Sticky notes')
72+
root.geometry('600x600')
73+
root.config(bg='#d3d3d3')
74+
root.iconbitmap("./favicon.ico")
75+
root.resizable(False, False)
76+
77+
# Fonts
78+
my_font = Font(
79+
family="Sans Serif",
80+
size=25,
81+
)
82+
83+
# Frame for list items
84+
notes_frame = Frame(root)
85+
notes_frame.pack(pady=10)
86+
87+
# Welcome Message
88+
start_msg = Label(notes_frame, text="Enter a note to get started...", font=(
89+
"Sans serif", 18), fg="darkgrey")
90+
start_msg.pack(side=TOP)
91+
92+
# Main ListBox for notes
93+
notes_list = Listbox(notes_frame,
94+
font=my_font,
95+
width=25,
96+
height=5,
97+
bd=0,
98+
bg="SystemButtonFace",
99+
selectbackground="grey",
100+
activestyle="none",
101+
highlightthickness=0
102+
)
103+
notes_list.pack(side=LEFT, fill=BOTH)
104+
105+
# Scrollbar for notes_frame
106+
scroll = Scrollbar(notes_frame)
107+
scroll.pack(side=RIGHT, fill=BOTH)
108+
109+
# Scrollbar configuration
110+
notes_list.config(yscrollcommand=scroll.set)
111+
scroll.config(command=notes_list.yview)
112+
113+
# Notes Entry Box
114+
notes_entry = Entry(root, font=("Sans Serif", 22), relief=FLAT, borderwidth=10)
115+
notes_entry.pack(pady=20)
116+
117+
# Button Frame
118+
function_button_frame = Frame(root, bg="#d3d3d3")
119+
function_button_frame.pack()
120+
121+
# Buttons
122+
add_button = Button(function_button_frame, text="Add note", command=add_note)
123+
delete_button = Button(function_button_frame,
124+
text="Delete note", command=delete_note)
125+
checked_button = Button(function_button_frame,
126+
text="Check item", command=check_note)
127+
unchecked_button = Button(function_button_frame,
128+
text="Uncheck item", command=uncheck_note)
129+
130+
add_button.grid(row=0, column=0)
131+
delete_button.grid(row=0, column=1, padx=10)
132+
checked_button.grid(row=0, column=2)
133+
unchecked_button.grid(row=0, column=3, padx=10)
134+
135+
# Error Message
136+
error = Label(root)
137+
138+
# Author Info
139+
author = Label(root, text="© Swaraj Baral\nGithub: SwarajBaral",
140+
bg="#d3d3d3", fg="grey")
141+
author.pack(side=BOTTOM)
142+
143+
if __name__ == '__main__':
144+
root.mainloop()

0 commit comments

Comments
 (0)