Python PyQt5: How to show an error message with PyQt5

前端 未结 6 1292
别那么骄傲
别那么骄傲 2020-12-15 13:00

In normal Python (3.x) we always use showerror() from the tkinter module to display an error message but what should I do in PyQt5 to display exactly the same message type a

6条回答
  •  失恋的感觉
    2020-12-15 13:50

    Qt includes an error-message specific dialog class QErrorMessage which you should use to ensure your dialog matches system standards. To show the dialog just create a dialog object, then call .showMessage(). For example:

    error_dialog = QtWidgets.QErrorMessage()
    error_dialog.showMessage('Oh no!')
    

    Here is a minimal working example script:

    import PyQt5
    from PyQt5 import QtWidgets
    
    app = QtWidgets.QApplication([])
    
    error_dialog = QtWidgets.QErrorMessage()
    error_dialog.showMessage('Oh no!')
    
    app.exec_()
    

提交回复
热议问题