Coders Packet

Creating notepad using Tkinter GUI in Python

By Ayush Kumar JHA

This is a simple notepad that being created in Python using Tkinter library, which helps us to SAVE, CLEAR, and OPEN our files in notepad

output of notepad codeFirst, we will start by making the interface of our Tkinter, by importing essential libraries,  setting the padding, border and desired background colour.

from tkinter import *
from tkinter import filedialog

frame = Frame(root)


After that, in the second process we will be designing buttons for our operation that notepad will do for us, like:

->SAVE: this function let us save the file we wrote on the notepad

->CLEAR: this function let us clear the whole page.

->OPEN: this function will let us to open the file which is already stored in our file manager.

b1=Button(root,  text="SAVE", command=save_file, bg="orange"), y=10)

b2=Button(root,  text="CLEAR", command=clear_file, bg="white"), y=10)

b3=Button(root,  text="OPEN", command=open_file, bg="green"), y=10)

entry=Text(root, height=33, width=58, wrap=WORD), y=50)



Now, when we are ready with all our commanding buttons and everything, we will enable these buttons by giving them commands to do their assigned work.

def save_file():
    open_file=filedialog.asksaveasfile(mode='w',  defaultextension=".txt") 
    if open_file is None:
    text=str(entry.get(1.0 , END))
def clear_file():
    entry.delete(1.0, END)
def open_file():
    file=filedialog.askopenfile(mode='r', filetype=[('text files', '*.text')])
    if file is not None:
    entry.insert(INSERT, content )


Download Complete Code


No comments yet