从线程打开PyQt窗口

时间:2016-01-27 13:21:04

标签: python python-3.x tornado pyqt5

我正在尝试使用组合龙卷风websocket和PyQt窗口来做python应用程序 当我收到来自websocket的消息时,我需要打开PyQt窗口,但我的程序总是掉下来。 有什么优雅的方法怎么做?

控制器

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_())

服务器

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 ***

感谢您的帮助

0 个答案:

没有答案