如何顯示窗口+打印那個文本?如果我有我的while循環,它不再顯示窗口。Python - 如何顯示窗口+打印文本?哪裏只有打印但沒有顯示窗口
import sys
import datetime
import time
from PyQt4 import QtCore, QtGui
class Main(QtGui.QMainWindow):
def __init__(self, parent=None):
super(Main, self).__init__(parent)
self.b = QtGui.QPushButton("exit", self, clicked=self.close)
self.c = QtGui.QLabel("Test", self)
if __name__ == "__main__":
app=QtGui.QApplication(sys.argv)
myapp=Main()
myapp.show()
while True:
time.sleep(2)
print "Print this + Show the Window???!!!"
sys.exit(app.exec_())
嘗試:
import sys
import datetime
import time
from PyQt4 import QtCore, QtGui
class Main(QtGui.QMainWindow):
def __init__(self, parent=None):
super(Main, self).__init__(parent)
self.b = QtGui.QPushButton("exit", self, clicked=self.close)
self.c = QtGui.QLabel("Test", self)
def myRun():
while True:
time.sleep(2)
print "Print this + Show the Window???!!!"
if __name__ == "__main__":
app=QtGui.QApplication(sys.argv)
myapp=Main()
myapp.show()
thread = QtCore.QThread()
thread.run = lambda self: myRun()
thread.start()
sys.exit(app.exec_())
輸出:
類型錯誤:()採用完全1參數(0給出)
可能重複(http://stackoverflow.com/questions/3765384/pyqt-how-do-i-handle-loops-in-main) –
@Aaron Digulla:請參閱上文,不工作的應用線程。 – YumYumYum