Desktop Notepad App using Tkinter
Intermediate1) Project Overview
This project will teach you how to create your own desktop notepad application — similar to the Windows Notepad — using Python's Tkinter library.
The Notepad app will allow users to:
- Create a new file
- Open and edit existing text files
- Save files with a custom name
- Cut, copy, and paste text
- Exit the application safely
This is a GUI-based project, helping you move beyond console-based programs into desktop software development.
2) Learning Objectives
By completing this project, you will learn to:
- Use the Tkinter library to build GUI applications
- Implement menus, text areas, and file dialogs in Tkinter
- Handle file operations such as open, save, and new file creation
- Use events, functions, and classes together to make modular code
- Work with clipboard operations like cut, copy, and paste
3) Step-by-Step Explanation
Follow these steps to build the notepad app:
- Import Tkinter modules – You'll need tkinter, filedialog, and messagebox
- Create the main window – Initialize the Tkinter app and set window title and size
- Add a Text widget – This serves as the main typing area
- Create a Menu bar – Add options like "File", "Edit", and "Help"
- Implement File Menu Functions – Add commands for New, Open, Save, and Exit
- Implement Edit Menu Functions – Add Cut, Copy, Paste actions using clipboard methods
- Link the menu to the window – Use config(menu=menubar) to attach it
- Run the main event loop – Keep the GUI running with root.mainloop()
4) Complete Verified Python Code
You can copy this into a file named notepad_app.py and run it.
# ------------------------------
# Desktop Notepad App using Tkinter
# Verified and Tested Code
# ------------------------------
import tkinter as tk
from tkinter import filedialog, messagebox
import os
class NotepadApp:
def __init__(self, root):
self.root = root
self.root.title("Python Notepad")
self.root.geometry("700x500")
self.root.iconbitmap("") # You can add a .ico file path here if desired
self.filename = None
# Create Text Area
self.text_area = tk.Text(self.root, undo=True, wrap='word')
self.text_area.pack(fill=tk.BOTH, expand=1)
# Create Menu Bar
self.menubar = tk.Menu(self.root)
self.root.config(menu=self.menubar)
# --- File Menu ---
filemenu = tk.Menu(self.menubar, tearoff=0)
self.menubar.add_cascade(label="File", menu=filemenu)
filemenu.add_command(label="New", command=self.new_file)
filemenu.add_command(label="Open", command=self.open_file)
filemenu.add_command(label="Save", command=self.save_file)
filemenu.add_separator()
filemenu.add_command(label="Exit", command=self.exit_app)
# --- Edit Menu ---
editmenu = tk.Menu(self.menubar, tearoff=0)
self.menubar.add_cascade(label="Edit", menu=editmenu)
editmenu.add_command(label="Cut", command=self.cut_text)
editmenu.add_command(label="Copy", command=self.copy_text)
editmenu.add_command(label="Paste", command=self.paste_text)
# --- Help Menu ---
helpmenu = tk.Menu(self.menubar, tearoff=0)
self.menubar.add_cascade(label="Help", menu=helpmenu)
helpmenu.add_command(label="About", command=self.show_about)
# ---------------- File Menu Functions ----------------
def new_file(self):
self.text_area.delete(1.0, tk.END)
self.filename = None
self.root.title("Untitled - Python Notepad")
def open_file(self):
file_path = filedialog.askopenfilename(defaultextension=".txt",
filetypes=[("Text Documents", "*.txt"), ("All Files", "*.*")])
if file_path:
self.filename = file_path
self.root.title(os.path.basename(file_path) + " - Python Notepad")
with open(file_path, "r", encoding="utf-8") as file:
content = file.read()
self.text_area.delete(1.0, tk.END)
self.text_area.insert(1.0, content)
def save_file(self):
if self.filename:
content = self.text_area.get(1.0, tk.END)
with open(self.filename, "w", encoding="utf-8") as file:
file.write(content)
else:
self.filename = filedialog.asksaveasfilename(initialfile="Untitled.txt",
defaultextension=".txt",
filetypes=[("Text Documents", "*.txt"), ("All Files", "*.*")])
if self.filename:
with open(self.filename, "w", encoding="utf-8") as file:
file.write(self.text_area.get(1.0, tk.END))
self.root.title(os.path.basename(self.filename) + " - Python Notepad")
def exit_app(self):
ask = messagebox.askyesno("Exit", "Do you want to exit Notepad?")
if ask:
self.root.destroy()
# ---------------- Edit Menu Functions ----------------
def cut_text(self):
self.text_area.event_generate("<>" )
def copy_text(self):
self.text_area.event_generate("<>" )
def paste_text(self):
self.text_area.event_generate("<>" )
# ---------------- Help Menu ----------------
def show_about(self):
messagebox.showinfo("About Notepad", "Python Notepad v1.0\nDeveloped using Tkinter\nBy: Tajammul Hussain")
# ---------------- Main Application ----------------
if __name__ == "__main__":
root = tk.Tk()
app = NotepadApp(root)
root.mainloop()
✅ Libraries used: tkinter (built-in)
✅ Verified: No syntax errors, full GUI functionality working (New, Open, Save, Cut, Copy, Paste, Exit)
5) Output Example
When you run the program, a window titled "Python Notepad" appears with:
- A large text area to type notes
- Menus: File, Edit, and Help at the top
1. Type some text.
2. Click File → Save, name it my_notes.txt.
3. Close and re-open with File → Open.
4. Use Edit → Cut/Copy/Paste as needed.
💡 A pop-up appears when you click "About" in the Help menu.
6) Extension Challenge
Make your notepad more advanced
Goal: Add one or more of these features to make your app more professional and user-friendly:
- Add Dark Mode / Light Mode toggle
- Add a Find & Replace tool using simpledialog
- Add font customization (bold, italic, font size)
- Add autosave after every few seconds using after() method
7) Summary
You've now built a fully functional desktop notepad using Python's Tkinter library.
Through this project, you've practiced:
- GUI development
- Event handling
- File I/O
- Code modularization using classes
This project bridges the gap between console applications and real desktop software — preparing you for more advanced GUI frameworks like PyQt or Kivy in the future.
Keep building — your next step could be a Text Editor with Syntax Highlighting or Auto-Save!