Skip to content

How to create Notepad in Python using Tkinter module.

Published: at 01:10 AM

This notepad GUI consist of various menu such as file and edit, using which all functionalities like saving the file, opening a file, editing,cut and paste can be done. For running this application you have to install Tkinter python package.

pip install tk

let’s start with some neccessary imports imports for creating Notepad with Tkinter python

now lets create class for notepad and start with creating a window surface with tkinter.

after creating defaut window width and height, let’s add a scrollbar and create a function for icon.

after that let’s append our code with setting the window title text “untitled — Notepad” and make the windows alignments with the use of screenwidth and screenheight method. Also for making geometry and making textarea auto resizable ,we will code as shown below.

Now, we are going to add commands:

  1. New = New file
  2. Open = Open file
  3. Save = Save file
  4. Exit = quite Application
  5. Cut
  6. copy
  7. paste

And also cascade for them. which are Edit for cut, copy and paste & File is for New, open, save And Exit.

Next, we are going to add description of the notepad by adding command About Notepad and cascading it in Help menu.

For making scrollbar area adjust automatically with respect of content of file, we use config as shown below.

Now lets create functions for quite application, show about, open file, New file and Save file.

Also create function for cut copy paste.

lastly in class Notepad lets create a function to run the main loop and lets run() Notepad.

In case you got stuck somewhere in code, visit to my github repository and go through the code. The link is :

immodded/notepad