PyQt5 Tutorials
About Lesson

This is the second lesson in Python PyQt5, in this lesson we want tp learn about Python PyQt5 QPushButton. the QPushButton widget provides a command button. The push button, or command button, is perhaps the most commonly used widget in any graphical user interface. Push (click) a button to command the computer to perform some action, or to answer a question. Typical buttons are OK, Apply, Cancel, Close, Yes, No and Help.

 

 

First of all we need to add our imports, basically we can use QPushButton class for creating of Button in PyQt5.

 

 

Using this code we can set the geometry for the window. you need to add the x, position of the window, width and height of the window.

 

 

For setting the window title you need to use this line of code.

 

 

If you want to add an icon in your window, you can use this code, make sure that you have already added an icon in your working directory.

 

 

So you can create pyqt5 buttons by creating the object of QPushButton.

 

 

Sometimes you need to set the width and height of the QPushButton, you can use this code.

 

 

If you want to set an icon for the Python PyQt5 QPushButton than you do it like this.

 

This is the complete source code for PyQt5 How to Create QPushButton

 

 

 

Run the complete code and this is will be the result.

PyQt5 How to Create QPushButton
PyQt5 How to Create QPushButton