Course Content
PyQt5 Basics – Installation Process, Qt Designer Intro
In this part we are going to talk about some basics functionalities in PyQt5, we go through installation process, creating QPushButton, Signals and working with Qt Designer.
0/4
PyQt5 Tutorials
About Lesson

In this PyQt5 Menu tutorial we are going to learn about Creating QMenu in PyQt, so pyqt5 QMenu class provides a menu widget for use in menu bars, context menus, and other popup menus.

Now open your Qt Designer,  you can just write pyqt5designer in your terminal, after opening the Qt Designer you need to create MainWindow. because when you want to create menus or status bars you need to use QMainWindow, now we want to create our menu and menu items.

 

 

This is the design.

PyQt5 QMenu Design
PyQt5 QMenu Design

 

 

After completing the design you need to save the .ui file, iam going to name it menu.ui, now copy the file and paste it in the Scripts folder of your Python installation, because we want to convert our ui file in to python file and for converting you need to use pyuic5 module. pyuic5 module is located in the Scripts folder of your Python installation, run this command for converting in your terminal.

 

 

 

And This is the converted code also we have added some icons to the menu items.

 

 

 

Run the complete code and this is the result.

PyQt5 Menu - Creating QMenu in PyQt
PyQt5 Menu – Creating QMenu in PyQt

Creating PyQt QMenu with Coding 

OK now we want to create our pyqt5 menu using coding, in the previous part we have used Qt Designer, in here we are not going to use Qt Designer. this is the complete source code.

 

 

 

These are our window requirements like window title, window icon, width and height of the window, x and y position of the window.

 

 

 

In here we have created menubar and we have added a File menu in the menubar.

 

 

This is for creating the menu item, and we can use QAction for this, also you can see that we have added icon for the menu item.

 

 

Also you can use the triggered() signal of menu item for adding functionlaity to the menu item.

 

 

 

Run the complete code and this is the result.

 Creating QMenu in PyQt
Creating QMenu in PyQt
Thank you for visiting my website! If you enjoyed the free courses, please consider supporting my works on Patreon.
Exercise Files
No Attachment Found
No Attachment Found