我需要ProgressBar
小部件在my_app中,當我點擊pushButton
時,我不能在def download (self)
中調用def call_progressBar2(self,value1)
。 任何人都可以幫助我嗎?如何從Python中的Main類調用GUI函數?
main.py
from g import Ui_MainWindow
from PyQt4 import QtCore, QtGui
import sys
import time
from b import classb
class MainWindow(QtGui.QMainWindow):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
instance_b=classb()
tvt= self.call_progressBar2(self)
QtCore.QObject.connect(self.ui.pushButton1, QtCore.SIGNAL("clicked()"), \
lambda: instance_b.download(tvt))## I need help here.
def call_progressBar2(self,value1):
while True:
time.sleep(0.05)
value = self.ui.progressBar.value() + 1
self.ui.progressBar.setValue(value)
QtGui.qApp.processEvents()
if (not self.ui._active or
value >= self.progressBar.maximum()):
if value==value1:
break
self.ui._active = False
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
myapp = MainWindow()
myapp.show()
sys.exit(app.exec_())
b.py
import time
from PyQt4 import QtCore, QtGui
class classb (object):
def __init__(self, parent=None):
self.parent=parent
#I need call def call_progressBar2() here.
def download(self):
from main import MainWindow
instance_m= MainWindow
print 'a'
instance_m.call_progressBar2(20)
print 'b'
instance_m.call_progressBar2(40)
print 'c'
instance_m.call_progressBar2(60)
print 'd'
instance_m.call_progressBar2(100)
不錯......非常感謝您.... –
您能幫我嗎?這裏http://stackoverflow.com/questions/34967007/how-can-i-make-new-thread-in-python –