🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101

Notepad-style text editor

A simple text editor with open, save, find and replace, word count and an unsaved-changes warning.

Beginner⏱ 5–7 hoursđŸĒœ 7 stepsPythonTkinter

What you'll learn

  • ◆Menus and dialogs in Tkinter
  • ◆File handling with encodings
  • ◆Text widget tags and search

What you'll build

  • ✓New, Open, Save, Save As
  • ✓Find and replace with highlights
  • ✓Word and line count in a status bar
  • ✓Warns before closing unsaved work

Step-by-step guide

  1. 1

    Build the layout

    A Text widget with a Scrollbar, a Menu bar (File, Edit, View) and a Label at the bottom as status bar.

  2. 2

    Open and save files

    Use filedialog.askopenfilename / asksaveasfilename and open files with encoding="utf-8".

  3. 3

    Track changes

    Bind <<Modified>> to mark the document dirty and show "*" in the window title.

  4. 4

    Find and replace

    Use text.search(pattern, start, stopindex="end") in a loop, tag matches with text.tag_add("found", ...) and highlight with tag_config.

  5. 5

    Status bar

    On every key release, count words with len(text.get("1.0", "end").split()) and show line:column from text.index("insert").

  6. 6

    Safe close

    root.protocol("WM_DELETE_WINDOW", on_close) and ask "Save changes?" with messagebox.askyesnocancel.

  7. 7

    Shortcuts

    Bind Ctrl+S, Ctrl+O, Ctrl+F and Ctrl+N.

🚀 Make it stand out

  • +Tabs for multiple files with ttk.Notebook
  • +Basic Python syntax highlighting with tags
  • +Auto-save every minute