PyQt5 is one of the most advanced GUI library for Python. While being powerful, it’s also well structured and makes it easy for you to build ‘advanced’ items. Custom widgets in PyQt5 is a breeze.
The below has a well-described way of building custom Widgets with PyQt5,
The Main Window
Let’s start by creating our main window. We go the OOP route right from the start. An OOP-less way is a pain for maintenance. Our skeleton looks like this
which outputs to
A Normal App
Let’s add a textbox and a label that just echoes whatever we type.
Our main window turns to this:
which outputs to
An empty widget looks like this:
Let’s name it as EchoText and add what we added to our main window
Using Like A Normal Widget
In our main window, leave only the skeleton and add the following:
and it gets displayed as when we coded everything in the main window itself.
The Complete App
Here’s the complete code for the entire application
Try creating a different widget and adding it. PyQt5 sounds tougher than Tkinter to get started but it’s worth it!
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.
- Widgets in ipython - Numeric Widgets
- Django form field custom widgets
- PyQt5 QDockWidget – Setting Multiple Widgets Inside it
- Creating custom user model using AbstractUser in django_Restframework
- Creating custom user model API extending AbstractUser in Django
- Python Tkinter | Create LabelFrame and add widgets to it
- Python | Multiple Sliders widgets Controlling Background Screen or WindowColor in Kivy
- How to use multiple UX Widgets in kivy | Python
- What are Widgets in Tkinter?
- PyQtGraph – Adding Qt Widgets with the Bar Graph
- PyQt5 QSpinbox - Dragging text from it and dropping it to Custom Label
- PyQt5 QCalendarWidget - Setting Custom Shortcuts to go Specific Month
- PyQt5 QCalendarWidget - Setting Custom Event
- PyQt5 QColorDialog - Setting Custom Color
- PyQt5 QColorDialog - Getting Custom Color
- PyQt5 QColorDialog - Custom Color Count
- PyQt5 - Creating String Spin Box
- Creating a tabbed browser using PyQt5
- Creating a simple browser using PyQt5
- Creating NotePad using PyQt5 - Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.