If the user choses yes, meaning they really did want to quit, we go ahead and issue the sys.exit as before. If they said no, then we just pass and the application resumes. Only one can be chosen.Īfter that, we have some simple if else logic that checks to see what the user picked. Here, the | denotes an either-or situation. The parameters here are self, window title, window message, and then finalyl the window options.
There are exclamation point versions, and so on. There are many message boxes, this question version comes with a question mark image to denote that the window is a question. This is a pre-made message box window that comes with PyQT. Since we are going to have this message pop up when the user tries to exit, let's put this code in the close_application method: def close_application(self):Ĭhoice = (self, 'Extract!', There are many reasons why we may want to double check that the user isn't messing up. Maybe the user is trying to delete the entire database of their contacts. Maybe the user just miss-clicked and doesn't actually want to exit. We're going to add a sort of "are you sure you want to exit" message when the user attempts to quit our application.
There may be all sorts of reasons why you may want to warn the user regarding an action they are trying to make.
In this tutorial, we're going to cover how to create a pop up window for messages like warnings to the user in PyQT.