Skip to content

Commit 215c7ce

Browse files
authored
Autocomplete Notes App with GUI (DhanushNehru#304)
* Added Automatic Notes App * Added Readme file
1 parent c20547e commit 215c7ce

File tree

4 files changed

+10121
-0
lines changed

4 files changed

+10121
-0
lines changed

Autocomplete Notes App/README.md

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Autocomplete Notes App
2+
3+
## Overview
4+
5+
The Autocomplete Notes App is a simple graphical user interface (GUI) application that allows users to take notes efficiently. It features an autocomplete functionality, where suggestions for completing words are displayed as the user types. This app is built using Python and the Tkinter library for the GUI, with the addition of word suggestions from a predefined word list.
6+
7+
## Features
8+
9+
- **Text Input**: A large text area for users to enter notes.
10+
- **Autocomplete**: As users type, a suggestion box displays the full word based on the entered text.
11+
- **Tab Functionality**: Users can press the Tab key to automatically fill in the suggested word into the text area.
12+
- **Save Notes**: Users can choose a filename to save their notes to a `.txt` file.
13+
- **Dynamic Sizing**: The app window resizes based on user actions.
14+
15+
## Requirements
16+
17+
- Python 3.x
18+
- Tkinter (usually comes pre-installed with Python)
19+
- A `wordlist.txt` file containing words for autocomplete suggestions.
20+
21+
## Installation
22+
23+
1. Clone the repository or download the source code files.
24+
2. Ensure you have Python 3.x installed on your machine.
25+
3. Make sure `wordlist.txt` is in the same directory as the application code. This file should contain words, each on a new line.
26+
27+
## Usage
28+
29+
1. Open a terminal or command prompt and navigate to the directory containing the application code.
30+
2. Run the application using the command:
31+
```bash
32+
python app.py

Autocomplete Notes App/app.py

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import tkinter as tk
2+
from tkinter import filedialog, messagebox
3+
4+
class AutocompleteApp:
5+
def __init__(self, root):
6+
self.root = root
7+
self.root.title("Autocomplete Notes App")
8+
9+
# Load words from wordlist.txt
10+
self.autocomplete_list = self.load_wordlist("wordlist.txt")
11+
12+
self.create_widgets()
13+
14+
def load_wordlist(self, filename):
15+
"""Load words from a specified file."""
16+
try:
17+
with open(filename, 'r') as file:
18+
words = [line.strip() for line in file.readlines() if line.strip()]
19+
return words
20+
except FileNotFoundError:
21+
messagebox.showerror("Error", f"File '{filename}' not found.")
22+
return []
23+
24+
def create_widgets(self):
25+
self.large_entry = tk.Text(self.root, wrap=tk.WORD)
26+
self.large_entry.grid(row=0, column=0, padx=10, pady=10, sticky="nsew")
27+
28+
self.suggestion_entry = tk.Entry(self.root, width=60, state='readonly')
29+
self.suggestion_entry.grid(row=1, column=0, padx=10, pady=5, sticky="ew")
30+
31+
self.save_button = tk.Button(self.root, text="Save Notes", command=self.save_notes)
32+
self.save_button.grid(row=2, column=0, padx=10, pady=5, sticky="ew")
33+
34+
self.root.grid_rowconfigure(0, weight=1)
35+
self.root.grid_columnconfigure(0, weight=1)
36+
37+
self.large_entry.bind("<KeyRelease>", self.update_suggestion)
38+
self.large_entry.bind("<Tab>", self.insert_complete_word)
39+
40+
def update_suggestion(self, event):
41+
"""Update the suggestion based on the current input."""
42+
current_input = self.get_last_word()
43+
suggestion = ""
44+
45+
if current_input:
46+
matches = [word for word in self.autocomplete_list if word.startswith(current_input)]
47+
if matches:
48+
suggestion = matches[0]
49+
50+
self.suggestion_entry.config(state='normal')
51+
self.suggestion_entry.delete(0, tk.END)
52+
self.suggestion_entry.insert(0, suggestion)
53+
self.suggestion_entry.config(state='readonly')
54+
55+
def get_last_word(self):
56+
"""Get the last word from the current line of the large entry."""
57+
cursor_index = self.large_entry.index(tk.INSERT)
58+
line_number = cursor_index.split('.')[0]
59+
line_text = self.large_entry.get(f"{line_number}.0", f"{line_number}.end").strip() # Get the current line text
60+
words = line_text.split()
61+
return words[-1] if words else ""
62+
63+
def insert_complete_word(self, event):
64+
"""Insert the complete word into the large entry when Tab is pressed."""
65+
complete_word = self.suggestion_entry.get()
66+
if complete_word:
67+
cursor_index = self.large_entry.index(tk.INSERT)
68+
line_number = cursor_index.split('.')[0]
69+
line_text = self.large_entry.get(f"{line_number}.0", f"{line_number}.end").strip()
70+
words = line_text.split()
71+
if words:
72+
words[-1] = complete_word
73+
self.large_entry.delete(f"{line_number}.0", f"{line_number}.end")
74+
self.large_entry.insert(f"{line_number}.0", ' '.join(words))
75+
76+
return "break"
77+
78+
def save_notes(self):
79+
"""Save the notes to a file."""
80+
notes = self.large_entry.get("1.0", tk.END).strip()
81+
if notes:
82+
file_path = filedialog.asksaveasfilename(defaultextension=".txt",
83+
filetypes=[("Text files", "*.txt"),
84+
("All files", "*.*")])
85+
if file_path:
86+
with open(file_path, 'w') as file:
87+
file.write(notes)
88+
messagebox.showinfo("Success", "Notes saved successfully!")
89+
else:
90+
messagebox.showwarning("Warning", "No notes to save!")
91+
92+
if __name__ == "__main__":
93+
root = tk.Tk()
94+
app = AutocompleteApp(root)
95+
root.mainloop()

0 commit comments

Comments
 (0)