How to Make Notepad in Python using Tkinter

Create your own Notepad in Python using Tkinter! Follow this straightforward tutorial to build a functional text editor and enhance your coding skills

Its about how you can make a mini notepad in python using Tkinter Library. Mini Notepad can save and open the files. Amazing thing is that the script have size less than 1 kb only…

Tkinter is widely used basic Graphical Library for open source languages like python,pearl etc. thus  can take advantage from its small and easy library functions for DIY works.

By import the Tkinter module ,the simple gui is provided here…The source code for mini notepad script is here:


import Tkinter as tk
root = tk.Tk()
name = "untitled_test.txt"

def save():
global name
f = open(name,”w”)
txt = t1.get(1.0,tk.END)
f.write(txt)
f.close()
label.config(text=”saved sucessfully “+name)

def open_file():
tw = tk.Toplevel(root)
lo = tk.Label(tw,text= “enter name of file”).pack()
eo = tk.Entry(tw)
eo.pack()
def ok():
global name
name = eo.get()
fo = open(name,”r”)
t1.insert(tk.END,fo.read())
fo.close()
tw.destroy()
bo = tk.Button(tw,text= “ok”, command=ok).pack()
root.wait_window(tw)

label = tk.Label(root,text=”Enter text here”)
b1 = tk.Button(root, text=” save “, command= save)
b2 = tk.Button(root, text=” open “, command= open_file)
t1 = tk.Text(root, width=55, height=25)

label.pack()
t1.pack()
b1.pack()
b2.pack()

root.title(“Mini Notepad”)
root.resizable(250,250)
root.mainloop()