[PyQt] multiple dialog boxes simultaneously

Pradnyesh Sawant spradml at gmail.com
Thu Nov 29 06:21:15 GMT 2007


Hello,
I want to have multiple dialog boxes simultaneously. So I have a function,
which is the target for threading.Thread, and which creates a new dialog.
But I'm getting the following error:
ASSERT failure in QWidget: "Widgets must be created in the GUI thread.",
file kernel/qwidget.cpp, line 951

My code is as follows:

*********************************************************************
import time
import threading
import sys
from PyQt4 import QtGui, QtCore

class Journal(object):
    def __init__(self):
        self.thrLst = []
        self.app = None
        while True:
            time.sleep(1)
            thr = threading.Thread(target = self.makeEntry)
            self.thrLst.append(thr)
            thr.start()
    def makeEntry(self):
        if self.app is None:
            self.app = QtGui.QApplication(sys.argv)
        print 'inside makeEntry'

        dialog = Gui()
        sys.exit(dialog.exec_())
class Gui(QtGui.QDialog):
    def __init__(self, parent = None):
        QtGui.QDialog.__init__(self, parent)
        frameStyle = QtGui.QFrame.Sunken | QtGui.QFrame.Panel
        self.lCntr = QtGui.QLabel()
        loGrd = QtGui.QGridLayout()
        loGrd.addWidget(self.lCntr, 0, 0)
        self.setLayout(loGrd)
        self.setWindowTitle(self.tr("Counter"))


if __name__ == "__main__":
    jrnl = Journal()
*********************************************************************
What am I doing wrong?
-- 
warm regards,
Pradnyesh Sawant
--
Nothing clarifies your ideas like trying to write them down. --Montaigne
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20071129/27cd19e9/attachment-0001.bin


More information about the PyQt mailing list