機會是我太疲倦,需要睡覺,因爲我已經做了線程前,但突然間我穿過其中規定一個常見的錯誤來的:PyQt的多線程例子
'global name 'self' is not defined'.
這裏是碼之前,我輸入線程功能,
import thread
import time
import ystockquote
import Tkinter as tk
from threadexample import *
import sys
from PyQt4.QtGui import *
class Window(QtGui.QDialog):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_Dialog()
self.ui.setupUi(self)
style = QStyleFactory.create('Cleanlooks')
app.setStyle(style)
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
viewer = Window()
viewer.show()
sys.exit(app.exec_())
和在這裏它與被稱爲(start_stream
)穿線功能,
import thread
import time
import ystockquote
import Tkinter as tk
from threadexample import *
import sys
from PyQt4.QtGui import *
class Window(QtGui.QDialog):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_Dialog()
self.ui.setupUi(self)
style = QStyleFactory.create('Cleanlooks')
app.setStyle(style)
QtCore.QObject.connect(self.ui.startbutton, QtCore.SIGNAL('clicked()'),self.start_stream)
def start_stream(threadName, delay):
while True:
footsie = ystockquote.get_price('^FTSE')
self.ui.indexlabel.setText(footsie)
try:
thread.start_new_thread(start_stream, ("Now Streaming", 5,))
except:
self.ui.indexlabel.setText("Error")
while True:
pass
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
viewer = Window()
viewer.show()
sys.exit(app.exec_())
請編輯您的問題並修復代碼示例中的所有縮進, – ekhumoro