[PyQt] QMessageBox.question returns NoButton in python interactive

Luke Campagnola luke.campagnola at gmail.com
Thu Jun 27 19:36:28 BST 2019


Greetings,
I have found that when calling QMessageBox.question, the message box
flashes up briefly before disappearing and the call returns NoButton. This
behavior is present in both PyQt4 and PyQt5 (most recently tested on 5.9.2
from anaconda package), on windows (but not linux), and only if I have not
called QApplication.exec_() because I am running in an interactive python
shell.

Code to reproduce (run with python -i):

import sys
#from PyQt4 import QtGui as QtWidgets
from PyQt5 import QtWidgets

app = QtWidgets.QApplication([])

def msg():
   print(QtWidgets.QMessageBox.question(btn, "title", "message"))

btn = QtWidgets.QPushButton("show messagebox")
btn.clicked.connect(msg)
btn.show()

# message box works if event loop is started
# app.exec_()


Cheers,
Luke
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20190627/9c31766c/attachment.html>


More information about the PyQt mailing list