Creating NotePad using PyQt5 – Python
In this article we will see how we can create notepad using PyQt5.
Notepad is a generic text editor that allows you to create, open, edit, and read plaintext files.
PyQt5 is cross-platform GUI toolkit, a set of python bindings for Qt v5. One can develop an interactive desktop application with so much ease because of the tools and simplicity provided by this library.
Use this command to install PyQt5 :
pip install PyQt5
GUI Implementation Steps :
1. Create a Vertical layout
2. Create a QPlainTextEdit object and add it to the layout
3. Create a container i.e QWidget object
4. Set this vertical layout to the container
5. Create a status bar to show status tips
6. Create file menu bar and add file actions below is how file menu bar will look like
7. Create an edit menu bar and add various edit action to it, below is how edit menu bar will look like
8. Create two toolbar for file and edit actions, below is how the toolbars will look like
Back End Implementation Steps :
1. Create a path variable and set it to None
2. Add actions to each of the file menu actions these are same of toolbar actions as both share same actions
3. Create a critical method that shows the passed value in the pop up, it is used to show if any error occurs during saving or opening file
4. Create update title method that changes the window title according to the name of the file
5. Inside the file open action, create a try-except block that try to open the file and then update the title and path
6. Inside the save action if path is none call the save as method else save file to the path
7. Inside the save as method save the file at the selected path by user
8. Inside the print action print the file using QPrintDialog object
9. Inside the edit toggle bar action set the line wrap mode of editor according to the checked state
10. Similarly set action for undo, redo, cut, copy, paste and select all using the QPlainTextEdit object built in functions
Below is the implementation
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course