用我做的那个 eventlet-pyqt 可以这么玩。
$ sudo zypper in python3-eventlet python3-qt5
$ git clone
https://github.com/hgoldfish/eventlet-pyqt.git$ cd eventlet-pyqt
$ vi testwin.py
$ python3 testwin.py
import time # Used as a sleep timer.
from PyQt5 import QtCore, QtGui
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QTextBrowser, QVBoxLayout
from hgoldfish.utils import eventlet
eventlet.monkey_patch() # 开始魔术表演
class MainWindow(QWidget):
def __init__(self, parent=None):
QWidget.__init__(self, parent)
self.pushButton = QPushButton("click me!", self)
self.textEdit = QTextBrowser(self)
self.setLayout(QVBoxLayout())
self.layout().addWidget(self.textEdit)
self.layout().addWidget(self.pushButton)
self.pushButton.clicked.connect(self.sendMsg)
self.operations = eventlet.GreenletGroup() # 需要一个 greenet 管理器
@eventlet.spawnInGreenlet() # 把一个函数变成协程
def sendMsg(self, checked):
print("sendMsg")
# 这个函数里面可以任意写各种网络库和 time.sleep
self.textEdit.append('1\n')
time.sleep(2)
self.textEdit.append('2\n')
time.sleep(2)
self.textEdit.append('3\n')
if __name__ == "__main__":
import sys
app = QApplication(sys.argv)
windows = MainWindow()
windows.show()
eventlet.start_application()
【 在 feng321 (sfdf) 的大作中提到: 】
: import time # Used as a sleep timer.
: from guiTocmd import Ui_MainWindow
: #from pylab import *
: ...................
--
修改:hgoldfish FROM 110.85.22.*
FROM 110.85.22.*