Notepad for Python with Source Code

The Notepad for Python is an open-source project which is developed using Python Programming Language. This system is a simple GUI-based application created by using Python.

It used the Tkinter function for the Graphical User Interface.

Python Notepad Software Project Information

Project Name:Notepad for Python
Language/s Used:Python Console Based
Python version (Recommended):2.x or 3.x
Database:None
Type:Python App
Developer:IT SOURCECODE
Updates:0
Python on Notepad – Project Information

About The Project

A Notepad in Python is designed using tkinter and the project file contains(notepad.py). Tkinter is a graphical user interface library from Python from which we will create more than one GUI app.

The use of a tkinter will broaden a notepad-like text editor. The notepad will have a menu where we are able to create a new file, open an existing file, save the file, edit, cut,  copy, and paste.

This article is an open-source that allows the person to download and edit as consistent with their need.

Before you start to create a Python Notepad, make sure that you have Pycharm IDE installed on your computer.

Steps on How To Create A Notepad For Python

Time needed: 5 minutes

Notepad using Python with Source Code

  • Step 1: Create a Project Name.

    First step open the PyCharm IDE and click “File” and select “New Project” and then create a project name after that click the “create” button.Creating Project Name for Notepad

  • Step 2: Create a Python File.

    In the second step after creating a project name, “right” click the project name, and then click “New.” After that choose “Python File“.Creating Python file for Notepad

  • Step 3: Name the Python File.

    The third step after choosing the Python File name the file “notepad” and then click “Enter“.Naming Python file for Notepad

  • Step 4: The actual code.

    Now you can start coding, you are free to copy the code that being provided below.

Python Notepad Code Explanations

1. New File

Module for New File Functionality.

def new_file_logo(event=None):
global url
url = ''
text_editor.delete(1.0,tk.END)
file.add_command(label='new', image=new_logo ,compound=tk.LEFT, accelerator ='Ctrl+N',command=new_file_logo)

The code above is for the new file feature. If you click on a new file, it will open a new document. If you want to open a new document faster, just press Ctrl+N on your keyboard.

2. Open File

Module for Open File Functionality.

def open_file_logo(event=None):
global url
url = filedialog.askopenfilename(initialdir=os.getcwd(), title='Select File', filetypes=(('Text File', '*.txt'), ('All files', '*.*')))
try:
with open(url, 'r') as fr:
text_editor.delete(1.0, tk.END)
text_editor.insert(1.0, fr.read())
except FileNotFoundError:
return
except :
return
main_screen_window.title(os.path.basename(url))




file.add_command(label='Open', image=open_logo ,compound=tk.LEFT, accelerator ='Ctrl+O',command =open_file_logo)

In the code above, which is for the open file feature to open a document file on your computer. Pressing Ctrl+O on the keyboard lets you open more than one file at once.

3. Save

Module for Save Functionality.

ef save_file_logo(event=None):
global url
try:
if url:
content = str(text_editor.get(1.0,tk.END))
with open(url, 'w', encoding='utf-8') as fw:
fw.write(content)
else :
url = filedialog.asksaveasfile(mode='w', defaultextension='.txt', filetypes=(('Text File', '*.txt'),('All files','*.*')))
content = text_editor.get(1.0, tk.END)
url.write(content)
url.close()
except :
return


file.add_command(label='Save', image=save_logo, compound=tk.LEFT, accelerator ='Ctrl+S', command=save_file_logo)

In the code shown above, which is for the Save your document. Click FILE > Save, choose or browse to a folder, give your document a name in the File name box, and click Save or save your work as you go by pressing Ctrl+S.

4. Exit

Module for Exit Functionality.

def exit_module(event=None):
global url, text_changed
try:
if text_changed:
boxmessage = messagebox.askyesnocancel('Warning','Do you want to save the file')
if boxmessage is True :

if url:
content = text_editor.get(1.0,tk.END)
with open(url,'w',encoding='utf-8') as fw:
fw.write(content)
main_screen_window.destroy()
else:
content2 = str(text_editor.get(1.0,tk.END))
url = filedialog.asksaveasfile(mode='w',defaultextension='.txt',filetypes=(('Text File','*.txt'),('All files','*.*')))
url.write(content2)
url.close()
main_screen_window.destroy()
elif boxmessage is False:
main_screen_window.destroy()
else:
main_screen_window.destroy()
except:
return

file.add_command(label='Exit', image=exit_logo, compound=tk.LEFT, accelerator='Ctrl+Q', command=exit_module)

In the code above, “Exit” is a command line on the File menu that lets you close the Notepad application when you’re done working on your document.

Module for Search or Find Functionality.

def search_module(event=None):

def find():
word = entry_find.get()
text_editor.tag_remove('match','1.0',tk.END)
matches = 0
if word:
start_pos = '1.0'
while True:
start_pos = text_editor.search(word, start_pos, stopindex=tk.END)
if(not start_pos):
break
end_pos = f'{start_pos}+{len(word)}c'
text_editor.tag_add('match',start_pos,end_pos)
matches +=1
start_pos=end_pos
text_editor.tag_config('match',foreground='red',background='')

In the code shown above, which is for finding a word that will turn red if it is correct?

How To Run The Python Notepad with Source Code?

To run this project, you must have installed a Pycharm on your PC (for Windows). This article is for educational purposes only!

After downloading the project you must follow the steps below:

Step 1: Unzip the file or Extract the file

Step 2: Double-click the notepad

Step 3: The project is ready to run

Downloadable Source Code 

I have here the list of Best Python Project with Source code free to download for free, I hope this can help you a lot.

Conclusion

Notepad for Python with source Code is good for the student who wants to learn Python programming because this project contains a Graphical User Interface (GUI) and a users friendly.

It is easy to understand and manipulate this project and use it for education purposes only.

Leave a Comment