每次运行完 dowork 里面 creat 或者print 之后UI就会卡死。 不知道是什么问题。
还有就是点击开始后马上点停止 也会卡死UI。 点了开始等一会 在点停止就没事了。 而且一直都没事。 只存在第一次运行程序。
求大神解答 代码贴出来了!~
from PyQt5 import QtWidgets, QtCore
from PyQt5.QtCore import QThread
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from ui import Ui_Form
import sys, os
import jihuo_main
import twitter
from threading import Thread
import time
class myUIshow(QtWidgets.QWidget,Ui_Form):
s1 = QtCore.pyqtSignal()
s2 = QtCore.pyqtSignal()
def __init__(self):
super(myUIshow,self).__init__()
self.setupUi(self)
self.w=Worker(self)
self.th=QThread()
self.w.moveToThread(self.th)
self.s1.connect(self.w.doWork)
self.s2.connect(self.th.terminate)
self.pushButton.clicked.connect(self.begin)
self.count = 1
def stop(self):
self.s2.emit()
def begin(self):
if self.count:
self.th.start()
self.pushButton.setText(QtCore.QCoreApplication.translate("Form", "停止"))
self.count = 0
self.s1.emit()
else:
self.stop()
self.pushButton.setText(QtCore.QCoreApplication.translate("Form", "开始"))
self.label_6.setText('等待开始')
self.count = 1
def mybox(self):
QMessageBox.information(self,'错误提示','info',QMessageBox.StandardButtons(QMessageBox.Yes | QMessageBox.No))
class Worker(QObject):
#QThread workerThread;
def __init__(self,myUIshow):
self.ui=myUIshow
self.t = twitter.Twitter(self.ui)
super(Worker, self).__init__()
@QtCore.pyqtSlot()
def doWork(self):
self.t.creat()
#print('aa')
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
myshow = myUIshow()
myshow.show()
sys.exit(app.exec_())
Python
PyQt