Pop up message - PyQt with Python GUI Programming tutorial 7

preview_player
Показать описание
In this PyQT4 GUI application development tutorial, we cover how to add a pop up or warning message. It is a good idea to have a popup warning message if the user wants to do something that might be a mistake. Things like overwriting a file and closing the application are examples of things you may want to confirm with the user!

Рекомендации по теме
Комментарии
Автор

To add the close_application to the windows closing event, you will need to define the closing event:

def closeEvent(self, event):
     event.ignore()
     self.close_application()

BrianPeters
Автор

These have been very helpful tutorials as I am new to python. I've always embraced object oriented programming and would p like to learn more from your examples despite the fact that you've expressed otherwise. I hope that you continue to show us simple tips and tricks and that you continue to update your videos and playlist. They've been a massive help!

RicksterLuna
Автор

love the sound of your chuckle :")

peeetew
Автор

The best way to handle a X close event is to customize the built in closeEvent method of the QWidget, QMainWindow etc classes.

Thus we can reimplement (overwrite) the method anywhere after our __init__() method like so:

def __init__(self):
super(Window, self).__init__()
self.setGeometry(50, 50, 500, 300)
.
.
.

def closeEvent(self, event):
self.close_application()


Simple as that!

Remember it works because closeEvent is built into the QWidget classes so redefining it redirects the event to whatever we like.

dmcg
Автор

Oh I love you man, 5:06 was so funny as always :)
that's why i love your tutorials.

ayyoubx
Автор

To be able to close the main window create a new button and function displayBox() to display the messagebox and close the main app if choice == Yes.If you press No you'll be able to close the main app from the first button with the close_application() function

vVperXx
Автор

Try making the function close-application global(And place it before the class). Then run close_application like so

nomartin
Автор

you may use the aboutToQuit Signal of QApplication

dhao
Автор

At the time of quitting main window frame by clicking on [x] => RED close button
to get QMessageBox choices
all you need to add below function under class Window(QtGui.QMainWindow):

def closeEvent(self, event):
choice = QtGui.QMessageBox.question(self, "Exit!", "Are you sure?", QtGui.QMessageBox.Yes | QtGui.QMessageBox.No)
if choice == QtGui.QMessageBox.No:
event.ignore()
else:
print("closing!!")
event.accept()
sys.exit()

#PS - closeEvent is a inbuilt function under QCloseEvent, so we are just modifying it :)

sohom
Автор

def closeEvent(self, event):
if not type(event) == type(True):
event.ignore()
self.close_application()
this should be the code for closeEvent, unlike when we close the app through events (actions) defined by us where the event will be either True or False, when we try to close the app by hitting on the X icon, the system calls closeEvent with an event parameter which is not boolean

temporary_variable
Автор

Good info. 1 statement for doing all I need!!

mauroorio
Автор

Does Qt have a feature like canvas from Tk and will you teach it? I really like these Qt tutorial.

ihswap
Автор

Nice Tutorial! Found this while searching for a good gui module for me. It seems the best so far but at the Moment i have one big question in my mind.
How do I do stuff in the background?
I'm learning Python in school and have a bit of an understanding what Python is.
I could do it in a seperat thread but it semms wrong to outsource such small pieces of code.

I'm developing a Server/Client tool. They are connected over a SSL secured socket.
The client gets data and has to interpret it as well as display some of the stuff.

I hope you can solve this Problem in a Video in the next few days or give me a hint I can search for.

dinnyrandom
Автор

Hi, i would like to make a Pop-Up alert when i start my app, and i want it to say: "Welcome" and add an image, and then it closes by itself after, for example, 5 seconds . Does the method close_application do what i need? Thanks for your time, and your great videos.

flosh
Автор

I am checking a text box if its empty. If yes, I want to pop up a warning message. The message come up fine. But I don't want to quit the app. I just want to stop the user. Until he enters something in the text box. How to do that?

IsItTimeToTravel
Автор

@sentdex it would be wicked if you could do something on c++ and qt?

SuperReivan
Автор

"So let's hit the baby in the face"

theglowingman
Автор

what text editor you're using? it looks kinda cool ...

vuhoangdung
Автор

how do I create a text box that only accepts interger data types, and when entering a string data type an error command appears

digitaltutorial
Автор

I want to add a menu button to make up a dialog with the printer or at least just print on the printer without ant dialog, so how should I do it. Any advise would be great =)

vladislavkasintsev