感谢enginefree。
我做这个
class Window(QtGui.QDialog): def __init__(self, parent=None): super(Window, self).__init__() self.thread = ListenWebsocket() self.thread.start()...class ListenWebsocket(QtCore.QThread): def __init__(self, parent=None): super(ListenWebsocket, self).__init__(parent) websocket.enableTrace(True) self.WS = websocket.WebSocketApp("ws://localhost:8080/chatsocket", on_message = self.on_message, on_error = self.on_error, on_close = self.on_close) def run(self): #ws.on_open = on_open self.WS.run_forever() def on_message(self, ws, message): print message def on_error(self, ws, error): print error def on_close(self, ws): print "### closed ###"if __name__ == '__main__': app = QtGui.QApplication(sys.argv) QtGui.QApplication.setQuitonLastWindowClosed(False) window = Window() window.show() sys.exit(app.exec_())
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)