Skip to content

Latest commit

Β 

History

History
Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Β 
Β 
Β 
Β 
Β 
Β 

README.md

Notepad

Description

A simple yet functional text editor with a graphical user interface. Features file operations (open, save, new), text editing with syntax highlighting colors, and keyboard shortcuts. Styled with a terminal-inspired green-on-black theme.

Features

  • Create new files
  • Open existing files
  • Save files
  • Save as (new file name)
  • Clear text with confirmation
  • Word wrap enabled
  • Monospace font (Courier)
  • Terminal-style appearance (green on black)
  • Scrollbar for long documents
  • Status bar showing file operations
  • Keyboard shortcuts (Ctrl+S, Ctrl+O, Ctrl+N)
  • Multiple file type support (.txt, .py, etc.)
  • UTF-8 encoding support

Stack

  • Language: Python
  • Libraries:
    • tkinter (standard library - all widgets)
    • filedialog, messagebox (standard library)
    • tk==0.1.0
  • Complexity: Beginner-Intermediate

Installation

# Install dependencies
pip install -r requirements.txt

# Run the program
python main.py

Usage

Start the Application

python main.py

File Operations

Create New File

  • Click "πŸ“„ New" button
  • Or press Ctrl+N
  • Prompts to save current file if modified

Open File

  • Click "πŸ“‚ Open" button
  • Or press Ctrl+O
  • Select file from dialog
  • Supports .txt, .py, and all file types

Save File

  • Click "πŸ’Ύ Save" button
  • Or press Ctrl+S
  • Saves to current file or prompts for new name

Clear Text

  • Click "πŸ—‘οΈ Clear" button
  • Confirmation dialog appears
  • Clears all text from editor

Interface

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ [πŸ’Ύ Save] [πŸ“‚ Open] [πŸ—‘οΈ Clear] [πŸ“„ New]        β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                 β”‚
β”‚  Your text here...                              β”‚
β”‚                                                 β”‚
β”‚                                                 β”‚
β”‚                                                 β”‚
β”‚                                                 β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Status: Ready                                   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Keyboard Shortcuts

Shortcut Action
Ctrl+S Save file
Ctrl+O Open file
Ctrl+N New file
Ctrl+A Select all
Ctrl+C Copy
Ctrl+V Paste
Ctrl+X Cut
Ctrl+Z Undo
Ctrl+Y Redo

Color Scheme

Terminal Style

  • Background: Black (#000000)
  • Text: Green (#00FF00)
  • Selection Background: Red
  • Selection Text: White
  • Cursor: Violet
  • Button Frame: Dark Gray (#34495e)

Functions

save_file()

Saves current content to file. If no file is open, calls save_file_as().

save_file_as()

Opens save dialog to save with new filename.

open_file()

Opens file dialog and loads selected file content.

clear_text()

Clears all text after confirmation.

new_file()

Creates new file, prompts to save current file if modified.

File Types Supported

  • Text Files (.txt)
  • Python Files (.py)
  • All Files (.)

Can be extended to support:

  • Markdown (.md)
  • JSON (.json)
  • HTML (.html)
  • CSS (.css)
  • JavaScript (.js)

Customization

Change Color Scheme

Light Theme

self.text_area = Text(
    self.root,
    bg="white",
    fg="black",
    selectbackground="blue",
    selectforeground="white",
    font=("Arial", 11)
)

Dark Theme (Modern)

self.text_area = Text(
    self.root,
    bg="#1e1e1e",
    fg="#d4d4d4",
    selectbackground="#264f78",
    selectforeground="white",
    font=("Consolas", 11)
)

Change Font

self.text_area.config(font=("Arial", 12))  # Arial
self.text_area.config(font=("Consolas", 11))  # Consolas
self.text_area.config(font=("Monaco", 10))  # Monaco

Add Line Numbers

class LineNumbers(tk.Canvas):
    def __init__(self, *args, **kwargs):
        tk.Canvas.__init__(self, *args, **kwargs)
        self.textwidget = None

    def attach(self, text_widget):
        self.textwidget = text_widget
        
    def redraw(self, *args):
        self.delete("all")
        i = self.textwidget.index("@0,0")
        while True:
            dline = self.textwidget.dlineinfo(i)
            if dline is None:
                break
            y = dline[1]
            linenum = str(i).split(".")[0]
            self.create_text(2, y, anchor="nw", text=linenum)
            i = self.textwidget.index("%s+1line" % i)

Add Find and Replace

def find_text(self):
    search_term = simpledialog.askstring("Find", "Enter text to find:")
    if search_term:
        start_pos = '1.0'
        while True:
            start_pos = self.text_area.search(search_term, start_pos, END)
            if not start_pos:
                break
            end_pos = f"{start_pos}+{len(search_term)}c"
            self.text_area.tag_add("highlight", start_pos, end_pos)
            start_pos = end_pos
        self.text_area.tag_config("highlight", background="yellow")

Add Menu Bar

menubar = tk.Menu(self.root)
self.root.config(menu=menubar)

# File menu
file_menu = tk.Menu(menubar, tearoff=0)
menubar.add_cascade(label="File", menu=file_menu)
file_menu.add_command(label="New", command=self.new_file)
file_menu.add_command(label="Open", command=self.open_file)
file_menu.add_command(label="Save", command=self.save_file)
file_menu.add_separator()
file_menu.add_command(label="Exit", command=self.root.quit)

# Edit menu
edit_menu = tk.Menu(menubar, tearoff=0)
menubar.add_cascade(label="Edit", menu=edit_menu)
edit_menu.add_command(label="Cut", command=lambda: self.text_area.event_generate("<<Cut>>"))
edit_menu.add_command(label="Copy", command=lambda: self.text_area.event_generate("<<Copy>>"))
edit_menu.add_command(label="Paste", command=lambda: self.text_area.event_generate("<<Paste>>"))

Learning Outcomes

  • Tkinter GUI development
  • File I/O operations
  • Text widget manipulation
  • Dialog boxes (file, message)
  • Event binding and keyboard shortcuts
  • Widget layout and styling
  • Error handling in file operations

Future Enhancements

  • Syntax highlighting for code
  • Line numbers
  • Find and replace
  • Undo/redo functionality
  • Font size adjustment
  • Theme selection
  • Print functionality
  • Recent files list
  • Auto-save
  • Word count
  • Spell checker
  • Multiple tabs
  • Split view
  • Minimap
  • Code folding
  • Auto-completion

Common Issues

Text not saving

  • Check file permissions
  • Ensure disk space available
  • Verify file path is valid

Cannot open file

  • Check file exists
  • Verify file encoding (UTF-8 supported)
  • Check file permissions

Keyboard shortcuts not working

  • Ensure window has focus
  • Check OS-level shortcuts don't conflict

Comparison with Other Editors

Feature This Notepad Windows Notepad VS Code
File Operations βœ“ βœ“ βœ“
Syntax Highlighting βœ— βœ— βœ“
Line Numbers βœ— βœ— βœ“
Find/Replace βœ— βœ“ βœ“
Multiple Tabs βœ— βœ— βœ“
Lightweight βœ“ βœ“ βœ—
Cross-platform βœ“ βœ— βœ“

License

This project is open source and available for educational purposes.