如何显示窗口+打印该文本?如果我有我的while循环,它不再显示窗口。
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_())
输出:
TypeError: () 只需要 1 个参数(给定 0)