Пытаюсь сделать пример: http://www.commandprompt.com/community/pyqt/x3738 (Example 10-22. Python threads and a PyQt gui window). Вот он:
import sys, time
from threading import *
from qt import *
class TextThread(Thread):
def __init__(self, name, *args):
self.counter=0
self.name=name
apply(Thread.__init__, (self, ) + args)
def run(self):
while self.counter < 200:
print self.name, self.counter
self.counter = self.counter + 1
time.sleep(1)
class MainWindow(QMainWindow):
def __init__(self, *args):
apply(QMainWindow.__init__, (self,) + args)
self.editor=QMultiLineEdit(self)
self.setCentralWidget(self.editor)
self.thread1=TextThread("thread1")
self.thread2=TextThread("thread2")
self.thread1.start()
self.thread2.start()
def main(args):
app=QApplication(args)
win=MainWindow()
win.show()
app.connect(app, SIGNAL("lastWindowClosed()"),
app, SLOT("quit()"))
app.exec_loop()
if __name__=="__main__":
main(sys.argv)
Вот переделанное:
import sys, time
from threading import *
from PyQt4 import QtCore, QtGui
class TextThread(Thread):
def __init__(self, name, *args):
self.counter=0
self.name=name
apply(Thread.__init__, (self, ) + args)
def run(self):
while self.counter < 200:
print self.name, self.counter
self.counter = self.counter + 1
time.sleep(1)
class MainWindow(QtGui.QMainWindow):
def __init__(self, *args):
apply(QtGui.QMainWindow.__init__, (self,) + args)
self.editor=QtGui.QMultiLineEdit(self)
self.setCentralWidget(self.editor)
self.thread1=TextThread("thread1")
self.thread2=TextThread("thread2")
self.thread1.start()
self.thread2.start()
def main(args):
app=QtGui.QApplication(args)
win=MainWindow()
win.show()
app.connect(app, SIGNAL("lastWindowClosed()"),
app, SLOT("quit()"))
app.exec_loop()
if __name__=="__main__":
main(sys.argv)