我正在使用python。我在一個模塊Gui.Py中的Qtdesigner中創建了一個GUI。我有一個單獨創建的代碼模塊。現在有一個問題,我的代碼模塊中有一段時間在while循環中打印的方法。我想我的GUI textbrowser顯示按鈕單擊事件的打印的短信..我如何可以實時做到這一點.. 的示例代碼:在python中集成GUI模塊和後端代碼模塊
Gui..py文件
from PyQt4 import QtCore, QtGui
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
_fromUtf8 = lambda s: s
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName(_fromUtf8("Form"))
Form.resize(400, 211)
self.textBrowser = QtGui.QTextBrowser(Form)
self.textBrowser.setGeometry(QtCore.QRect(140, 10, 256, 192))
self.textBrowser.setObjectName(_fromUtf8("textBrowser"))
self.pushButton = QtGui.QPushButton(Form)
self.pushButton.setGeometry(QtCore.QRect(20, 80, 97, 27))
self.pushButton.setObjectName(_fromUtf8("pushButton"))
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
Form.setWindowTitle(QtGui.QApplication.translate("Form", "Form", None, QtGui.QApplication.UnicodeUTF8))
self.pushButton.setText(QtGui.QApplication.translate("Form", "PushButton", None, QtGui.QApplication.UnicodeUTF8))
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
Form = QtGui.QWidget()
ui = Ui_Form()
ui.setupUi(Form)
Form.show()
sys.exit(app.exec_())
現在樣品。 PY
import time
class A:
def somefunction(self):
i=0
while i<100:
print str(i)
i+=1
time.sleep(2)
if __name__=='__main__':
p=A()
p.somefunction()
請幫助我, 謝謝
謝謝大家,我明白了:) – 2012-04-01 06:08:22