Hello friends, this is Parviz and today is our 8th video in PyQt 5 GUI programming
In the last video we have covered the basics of Signal and Slots
In this video we are also going to cover the basics of Signal and Slots
Don't worry, we will cover the advanced topics of Signal and Slots in the further videos
This was from the previous video. We have made a simple Signal and Slot for this CLOSE button
You can see that if I click on this CLOSE button, the window is closed
This code is from the previous video. If you haven't watched that, I highly recommend that you watch that video and come back
Now in this video we are going to make this application a little complex
I want that when a user clicks the CLOSE button, there should be a message box that says
Are you sure you want to CLOSE? Yes or No. Ok, now let's get started
First of all I remove this CLOSE click and also I remove this because I want to write ALL
Now if I run this, you can see that there is no functionality in the CLOSE button
Now the first thing you need, you should define a function. I name it CLOSEApp and in here make a variable reply
QMessageBox, first of all you need, I have already imported this. You should import QMessageBox in your Qtify QWidget
Import QMessageBox. QMessageBox.question It takes some parameters
The first one is self. The second one is the title of message box
I give it CLOSEMessage. The third one is your message
I write, Are you sure? Are you sure to CLOSE? To CLOSE window
Ok, now I write in here. The fourth one is QMessageBox. The fourth one is our choice
The first one is I take Yes. Or QMessageBox.No QMessageBox.No
Like this. Now make our condition. If reply is equal to QMessageBox.Yes
If it is Yes, we want to CLOSE the window. Self.CLOSE Otherwise we don't do anything
Now in here you should connect this function to your button. In this section, write button.click
When a user click, remove this.connect And in here write your self.closeApp function
Remove this too. Now if I run this simple application. You can see that we have our window
And also we have our CLOSE button. Now if I click on the CLOSE button
You can see that I have a message box. And also CLOSEMessage icon
And here it's telling me that. Are you sure to CLOSE the window
If I click on No. The window is the same. But if I click the Yes
The window is closed. This was our 8th video. Don't worry we will cover the advance
Signal and slots. In the next videos. And also in the next video
We will cover complete QMessageBox. If you have any question. Please let me know
And if you like this video. Please like the video. And also please subscribe the channel