Free Download 2Python Project - Create Notepad editor with Python using Tkinter with source code

161 View
10 Downloads

In this simple python project we will develop a Notepad editor with Tkinter .Tkinter is Python GUI toolkit which will provide GUI interface. To create this notepad editor we need to add Tkinter library. This Project contains functionalities like

  • Create new File
  • Open new File
  • Save File
  • Exit Editor
  • Cut, Copy and Past functionalities

 

How to install Tkinter library?

To install Tkinter we need pre installed python, when we install python we need to check td/tk and IDLE checkbox which will install Tkinter library.

If we missed it while install python we can install Tkinter separately by run the pip command.

This Tkinter can be installed by pip, we need to run below command

pip install python-tk

 

 

Python Project - Notepad edito

 

This will download and install all required packages for Tkinter.

 

Now create python project and import required packages

import os
from tkinter import *
from tkinter.messagebox import *
from tkinter.filedialog import *


class Notepad:
    __root = Tk()

 

Here we have imported two other packages called messagebox and filedialog

MessageBox is used to show white box to write the content

Filedialog is used to show dialog with options when we tap on menu options

 

 

Create Menu options

# Add controls (widget)
self.__thisTextArea.grid(sticky=N + E + S + W)

# To open new file
self.__thisFileMenu.add_command(label="New",
                                command=self.__newFile)

# To open a already existing file
self.__thisFileMenu.add_command(label="Open",
                                command=self.__openFile)

# To save current file
self.__thisFileMenu.add_command(label="Save",
                                command=self.__saveFile)

# To create a line in the dialog
self.__thisFileMenu.add_separator()
self.__thisFileMenu.add_command(label="Exit",
                                command=self.__quitApplication)
self.__thisMenuBar.add_cascade(label="File",
                               menu=self.__thisFileMenu)

# To give a feature of cut
self.__thisEditMenu.add_command(label="Cut",
                                command=self.__cut)

# to give a feature of copy
self.__thisEditMenu.add_command(label="Copy",
                                command=self.__copy)

# To give a feature of paste
self.__thisEditMenu.add_command(label="Paste",
                                command=self.__paste)

# To give a feature of editing
self.__thisMenuBar.add_cascade(label="Edit",
                               menu=self.__thisEditMenu)

# To create a feature of description of the notepad
self.__thisHelpMenu.add_command(label="About Notepad",
                                command=self.__showAbout)
self.__thisMenuBar.add_cascade(label="Help",
                               menu=self.__thisHelpMenu)

 

Open a File

To open a file we need to add below code

def __openFile(self):

    self.__file = askopenfilename(defaultextension=".txt",
                                  filetypes=[("All Files", "*.*"),
                                             ("Text Documents", "*.txt")])

    if self.__file == "":

        # no file to open
        self.__file = None
    else:

        # Try to open the file
        # set the window title
        self.__root.title(os.path.basename(self.__file) + " - Notepad")
        self.__thisTextArea.delete(1.0, END)

        file = open(self.__file, "r")

        self.__thisTextArea.insert(1.0, file.read())

        file.close()

 

Like this we have included other functionalities in this project

 

 







Project Details

Project Type :  Desktop Application
Development Technologies :  Python
Tags :  Python, TKinter, Python Projects
Updated On :  2021-07-13
project Source Code Link :   Download Here