-
Notifications
You must be signed in to change notification settings - Fork 266
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Autocomplete Notes App with GUI (#304)
* Added Automatic Notes App * Added Readme file
- Loading branch information
Showing
4 changed files
with
10,121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Autocomplete Notes App | ||
|
||
## Overview | ||
|
||
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. | ||
|
||
## Features | ||
|
||
- **Text Input**: A large text area for users to enter notes. | ||
- **Autocomplete**: As users type, a suggestion box displays the full word based on the entered text. | ||
- **Tab Functionality**: Users can press the Tab key to automatically fill in the suggested word into the text area. | ||
- **Save Notes**: Users can choose a filename to save their notes to a `.txt` file. | ||
- **Dynamic Sizing**: The app window resizes based on user actions. | ||
|
||
## Requirements | ||
|
||
- Python 3.x | ||
- Tkinter (usually comes pre-installed with Python) | ||
- A `wordlist.txt` file containing words for autocomplete suggestions. | ||
|
||
## Installation | ||
|
||
1. Clone the repository or download the source code files. | ||
2. Ensure you have Python 3.x installed on your machine. | ||
3. Make sure `wordlist.txt` is in the same directory as the application code. This file should contain words, each on a new line. | ||
|
||
## Usage | ||
|
||
1. Open a terminal or command prompt and navigate to the directory containing the application code. | ||
2. Run the application using the command: | ||
```bash | ||
python app.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import tkinter as tk | ||
from tkinter import filedialog, messagebox | ||
|
||
class AutocompleteApp: | ||
def __init__(self, root): | ||
self.root = root | ||
self.root.title("Autocomplete Notes App") | ||
|
||
# Load words from wordlist.txt | ||
self.autocomplete_list = self.load_wordlist("wordlist.txt") | ||
|
||
self.create_widgets() | ||
|
||
def load_wordlist(self, filename): | ||
"""Load words from a specified file.""" | ||
try: | ||
with open(filename, 'r') as file: | ||
words = [line.strip() for line in file.readlines() if line.strip()] | ||
return words | ||
except FileNotFoundError: | ||
messagebox.showerror("Error", f"File '{filename}' not found.") | ||
return [] | ||
|
||
def create_widgets(self): | ||
self.large_entry = tk.Text(self.root, wrap=tk.WORD) | ||
self.large_entry.grid(row=0, column=0, padx=10, pady=10, sticky="nsew") | ||
|
||
self.suggestion_entry = tk.Entry(self.root, width=60, state='readonly') | ||
self.suggestion_entry.grid(row=1, column=0, padx=10, pady=5, sticky="ew") | ||
|
||
self.save_button = tk.Button(self.root, text="Save Notes", command=self.save_notes) | ||
self.save_button.grid(row=2, column=0, padx=10, pady=5, sticky="ew") | ||
|
||
self.root.grid_rowconfigure(0, weight=1) | ||
self.root.grid_columnconfigure(0, weight=1) | ||
|
||
self.large_entry.bind("<KeyRelease>", self.update_suggestion) | ||
self.large_entry.bind("<Tab>", self.insert_complete_word) | ||
|
||
def update_suggestion(self, event): | ||
"""Update the suggestion based on the current input.""" | ||
current_input = self.get_last_word() | ||
suggestion = "" | ||
|
||
if current_input: | ||
matches = [word for word in self.autocomplete_list if word.startswith(current_input)] | ||
if matches: | ||
suggestion = matches[0] | ||
|
||
self.suggestion_entry.config(state='normal') | ||
self.suggestion_entry.delete(0, tk.END) | ||
self.suggestion_entry.insert(0, suggestion) | ||
self.suggestion_entry.config(state='readonly') | ||
|
||
def get_last_word(self): | ||
"""Get the last word from the current line of the large entry.""" | ||
cursor_index = self.large_entry.index(tk.INSERT) | ||
line_number = cursor_index.split('.')[0] | ||
line_text = self.large_entry.get(f"{line_number}.0", f"{line_number}.end").strip() # Get the current line text | ||
words = line_text.split() | ||
return words[-1] if words else "" | ||
|
||
def insert_complete_word(self, event): | ||
"""Insert the complete word into the large entry when Tab is pressed.""" | ||
complete_word = self.suggestion_entry.get() | ||
if complete_word: | ||
cursor_index = self.large_entry.index(tk.INSERT) | ||
line_number = cursor_index.split('.')[0] | ||
line_text = self.large_entry.get(f"{line_number}.0", f"{line_number}.end").strip() | ||
words = line_text.split() | ||
if words: | ||
words[-1] = complete_word | ||
self.large_entry.delete(f"{line_number}.0", f"{line_number}.end") | ||
self.large_entry.insert(f"{line_number}.0", ' '.join(words)) | ||
|
||
return "break" | ||
|
||
def save_notes(self): | ||
"""Save the notes to a file.""" | ||
notes = self.large_entry.get("1.0", tk.END).strip() | ||
if notes: | ||
file_path = filedialog.asksaveasfilename(defaultextension=".txt", | ||
filetypes=[("Text files", "*.txt"), | ||
("All files", "*.*")]) | ||
if file_path: | ||
with open(file_path, 'w') as file: | ||
file.write(notes) | ||
messagebox.showinfo("Success", "Notes saved successfully!") | ||
else: | ||
messagebox.showwarning("Warning", "No notes to save!") | ||
|
||
if __name__ == "__main__": | ||
root = tk.Tk() | ||
app = AutocompleteApp(root) | ||
root.mainloop() |
Oops, something went wrong.