You typed notes into a Tkinter window, closed it, and they’re gone. Nothing wrote them to disk.
Quick answer: to make Tkinter save text to file, read the Text widget with text.get("1.0", "end-1c") and write that string with open(path, "w") inside a button callback:
with open(path, "w", encoding="utf-8") as f:
f.write(text.get("1.0", "end-1c"))
In this tutorial, we’ll build an order-notes window on Python 3.12.5 with Tk 8.6, add a Save As dialog and append to a log.
What You Need Before You Start
- Python 3 with Tkinter (the Windows installer includes it).
- A folder to write into, here
C:\pyguides\notes. - A button callback. See Tkinter Button commands.
Step 1: Save the Tkinter Text widget to a file
Our sample is a notes window for Harbor Lane Coffee:
import tkinter as tk
NOTES = r"C:\pyguides\notes\order_notes.txt"
root = tk.Tk()
root.title("Harbor Lane Coffee - Order notes")
root.geometry("580x300")
text = tk.Text(root, height=7, font=("Consolas", 11))
text.pack(fill="both", expand=True, padx=12, pady=(12, 6))
status = tk.Label(root, text="Not saved yet", anchor="w")
def save_notes():
content = text.get("1.0", "end-1c")
with open(NOTES, "w", encoding="utf-8") as f:
f.write(content)
lines = content.count("\n") + 1
status.config(text=f"Saved {lines} lines to order_notes.txt")
save = tk.Button(root, text="Save notes", command=save_notes)
save.pack(side="left", padx=12, pady=(0, 12))
status.pack(side="left", pady=(0, 12))
root.mainloop()

"1.0" means line 1, character 0. "end-1c" skips the newline Tk always adds. The with open() statement closes the file even if write() fails.
Step 2: Check what Tkinter wrote to the file
We read the file back in Command Prompt:
from pathlib import Path
notes = Path(r"C:\pyguides\notes\order_notes.txt")
print(notes.read_text(encoding="utf-8"))
print("Size on disk:", notes.stat().st_size, "bytes")
Output:
Order #2048 - Dana Whitfield
2 x Oat latte, 1 x Blueberry muffin
Total: $14.75
Pickup: Nov 6, 2026 at 8:30 AM
Size on disk: 112 bytes

Loading it back into a widget is in reading a text file in Tkinter.
Does asksaveasfilename save the file for you?
No. filedialog.asksaveasfilename() only returns a path. You write the file:
from tkinter import filedialog
def save_as():
path = filedialog.asksaveasfilename(
initialdir=r"C:\pyguides\notes",
defaultextension=".txt",
filetypes=[("Text files", "*.txt"), ("All files", "*.*")],
)
if not path: # Cancel returns an empty string
status.config(text="Save canceled")
return
with open(path, "w", encoding="utf-8") as f:
f.write(text.get("1.0", "end-1c"))
status.config(text=f"Saved to {path}")
We tested both branches: a picked path saved the text, and Cancel (an empty string) set the label to “Save canceled”.
defaultextension adds .txt when it’s missing. Other dialogs are in the Tkinter filedialog guide.
Step 3: Append Entry text to a log file
Same shop, now a call log. Mode "a" adds a line instead of replacing the file:
import tkinter as tk
LOG = r"C:\pyguides\notes\call_log.txt"
root = tk.Tk()
root.title("Harbor Lane Coffee - Call log")
root.geometry("580x170")
tk.Label(root, text="Call note:").pack(anchor="w", padx=12, pady=(14, 2))
entry = tk.Entry(root, font=("Segoe UI", 11))
entry.pack(fill="x", padx=12)
status = tk.Label(root, text="", anchor="w")
def add_note():
note = entry.get().strip()
with open(LOG, "a", encoding="utf-8") as f:
f.write(note + "\n")
entry.delete(0, "end")
status.config(text=f"Added: {note}")
add = tk.Button(root, text="Add to log", command=add_note)
add.pack(side="left", padx=12, pady=12)
status.pack(side="left")
root.mainloop()

After two clicks, call_log.txt held both lines:
Dana Whitfield moved pickup to 9:00 AM
Refunded $4.25 for a missing muffin
entry.get() needs no index arguments. More in getting Tkinter Entry text.
Tkinter save-to-file cheat sheet
| Goal | Code | Note |
|---|---|---|
| Read all Text content | text.get("1.0", "end-1c") | Skips Tk’s extra newline |
| Replace the file | open(path, "w") | Old content is lost |
| Add to the file | open(path, "a") | Creates it if missing |
| Ask for a path | filedialog.asksaveasfilename() | Returns “” on Cancel |
Common Mistakes to Avoid When Saving Tkinter Text
The most common one is reading to "end". In our test, "end" returned 'Total: $14.75\n', with a trailing newline, while "end-1c" returned 'Total: $14.75'.
Two more we’ve hit: a relative path like "notes.txt" lands in the current folder, and a missing folder raises FileNotFoundError. Create it first, as in creating a directory in Python.
Important: read the widget inside the callback. After mainloop() returns, get() raises TclError.
Next Steps
Add an Open button and a menu, and you’ve got the Python Tkinter text editor.
We’d keep these nearby for your next Tkinter screen:
- Python Tkinter Label
- Tkinter Checkbutton in Python
- Upload a file in Python Tkinter
- Python GUI programming with Tkinter
Frequently asked questions
How do I save text from a Tkinter Text widget to a file?
Call text.get("1.0", "end-1c") and write it with open(path, "w").
Why does my saved file have an extra blank line?
get("1.0", "end") includes Tk’s trailing newline. Use "end-1c" instead.
How do I add text to a file without overwriting it?
Open it in append mode, open(path, "a").
What’s the difference between asksaveasfilename and asksaveasfile?
asksaveasfilename returns a path string; asksaveasfile returns an open file object.
How do I know if the user canceled the Save dialog?
asksaveasfilename returns an empty string on Cancel.
Where are the file dialog options documented?
See Tkinter dialogs in the Python docs.

Bijay Kumar is a 13-time Microsoft MVP with more than 18 years in software development, and the founder of Python Guides and TSinfo Technologies. He started out building .NET and SharePoint solutions at HP, TCS and KPIT before moving into Python, machine learning and AI, and he also builds web apps with TypeScript and React. He writes the tutorials here himself, and every example is run before publishing so you see the real output. More about Bijay · Microsoft MVP profile · LinkedIn