Pyside2 GUI QPushButton With Signal And Slot

In this Pyside2 GUI Development iam going to show you creating of QPushButton With Signal And Slot. basically we are going to create a QPushButton and after that we are talking about Signal And Slots Mechanism. also before this we had some articles on Pyside2 GUI Development, you can check them in the below links.

 

 

Check Python GUI Development With Pyside2

 

1: Getting Started With Pyside2 | Qt For Python 

2: Pyside2 GUI Creating First Window 

3: Pyside2 GUI Creating Window Icon

4: Pyside2 GUI How To Create Icon Modes

5: Pyside2 GUI How To Create Tooltip

 

What is Signal And Slots ?

Signal and Slots are used for communication between some objects. a Signal is emitted when
a particular event occurs, and a Slot is called when its connected signal is emitted. so now
we are going to create an example of Pyside2 Signal and Slots.

 

So now this is the complete code for  Pyside2 GUI QPushButton With Signal And Slot

 

 

 

OK in the above code  first we have imported our classes from Pyside2 library

 

 

And this is our main window class that inherits from QWidget, in that class we are going to add the window title , window geometry and minimum width and height for the window.

also you can check Python Object Oriented Programming Articles in this link. Python Object Oreinted Programming. also we have added the setButton() method in this class.

 

 

 

Also this method is for setting our window icon

 

 

So this method is for creation of our QPushButton in Pyside2, also you can see that we have connected our clicked signal to the quiteApp slot that we are going to make it later.

 

 

Now this is our method or slot that we have connected this before to our clicked signal in the QPushButton

 

 

So in here every Pyside2 application must create an application object. The sys.argv parameter is a list of arguments from a command line.

Python scripts can be run from the shell. It is a way how we can control the startup of our scripts.

 

 

Finally, we enter the mainloop of the application. The event handling starts from this point. The mainloop receives events from the window system and dispatches them to the application widgets. The mainloop ends if we call the exit() method or the main widget is destroyed. The sys.exit() method ensures a clean exit. The environment will be informed how the application ended.

The exec_() method has an underscore. It is because the exec is a Python keyword. And thus, exec_() was used instead.

 

 

 

Run the complete code and this will be the result

 

Pyside2 GUI QPushButton With Signal And Slot
Pyside2 GUI QPushButton With Signal And Slot

 

 

 

Also you can watch the complete video for this article

 

 

Subscribe and Get Free Video Courses & Articles in your Email

 

Share via
Copy link
Powered by Social Snap
×