Khalsa Labs

Mini Notepad in Python using Tkinter

its about how to make a mini notepad in python using Tkinter.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 of scrip at yard is here:

mini_notepad


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()

The following two tabs change content below.
Python Developer and DIY lover.

want to comment ??

Your email address will not be published. Required fields are marked *