我正在python中使用PyQt4构建应用程序。我想添加一个背景计时器到我的应用程序,以便当计时器用完时,我的应用程序中的文本编辑器停止接收输入并冻结。 我曾尝试以下方法至今:PyQt中的后台计时器Python应用程序
def main():
app = QtGui.QApplication(sys.argv)
main = Main()
main.show()
start = time.time()
#this loop is for the time interval within which the text area of
#the editor will accept inputs.
while time.time() - start < 120:
pass
#this will set the text area to a read only state after and will not
#any more inputs.
main.text.setReadOnly(True)
sys.exit(app.exec_())
但每当我运行此应用程序停止响应。我也尝试通过线程运行计时器,但在这种情况下,应用程序也会停止响应。
我该如何实现此功能?
P.S. - 我是PyQt的初学者。
class Main(QtGui.QMainWindow):
def __init__(self,parent = None):
QtGui.QMainWindow.__init__(self,parent)
self.init_ui()
def init_ui(self):
self.text = QtGui.QTextEdit(self)
self.setCentralWidget(self.text)
self.statusbar = self.statusBar()
self.setGeometry(100,100,1080,720)
self.setWindowTitle("Text Editor")
这是淡化版本的主类代码。希望这可以帮助。
请张贴您的'类主'代码。 – DreyFax