1

I'am trying to do python app with combine tornado websocket and PyQt windows
I need to open PyQt window when I receive a message from websocket, but my program always fall down. Is any elegant way how to do it?

Controller:

class MainWindow(QtWidgets.QWidget, widget.Ui_Form):    
    def __init__(self):
        super(self.__class__, self).__init__()
        self.setupUi(self)
        self.message_window = None

 class Message(QtWidgets.QWidget, message.Ui_Form):
    def __init__(self, msg):
        super(self.__class__, self).__init__()
        self.setupUi(self, msg)  

if __name__ == "__main__":
    app = QtWidgets.QApplication(sys.argv)
    window = MainWindow()
    window.show()
    s = Server(window)
    s.start()
    exit(app.exec_())

Server:

class Server(QtCore.QThread):
def __init__(self, main_window):
    QtCore.QThread.__init__(self)
    self.msg_win = main_window.message_window

def run(self):
    self.msg_win = controller.Message("test")
    self.msg_win.show()
    *** starting tornado ***

Thanks for any help

Pavel D
  • 11
  • 3
  • Possible duplicate of [Updating GUI elements in MultiThreaded PyQT](http://stackoverflow.com/questions/9957195/updating-gui-elements-in-multithreaded-pyqt) – Mel Jan 27 '16 at 14:12
  • 2
    Widget, including windows, are not thread safe and should only be created/updated in the main thread. Instead `Server` should send a signal to `MainWindow`, which will then create/update widgets. – Mel Jan 27 '16 at 14:15

0 Answers0