我是python类的初学者,我对这段代码有点小问题(这是一段pyqt代码)。函数globalprogress是从另一个文件调用的,但是当他调用函数UpdateBar时,我的计算机一直告诉我,“Ui\IA object没有属性'progression'”,但那不是真的。你知道吗
有人知道我做错什么了吗? 非常感谢。你知道吗
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_IA(object):
def setupUi(self, IA):
IA.setObjectName("IA")
IA.resize(931, 570)
self.centralWidget = QtWidgets.QWidget(IA)
self.centralWidget.setObjectName("centralWidget")
self.progression = QtWidgets.QProgressBar(self.centralWidget)
self.progression.setGeometry(QtCore.QRect(50, 450, 831, 61))
self.progression.setProperty("value", 0)
self.progression.setObjectName("progression")
def UpdateBar(self):
self.progression.setValue(percentage)
def globalprogress(number):
global percentage
UIIA = Ui_IA()
percentage = int(number)
UIIA.UpdateBar()
试试看:
默认情况下不调用函数setupUI(),其中设置了progression属性。您可以使用
__init__()
,它将在实例化类(即创建类的对象)时自动运行,或者强制setupUI()在globalprogress()函数中运行。你知道吗在执行
UpdateBar()
之前,必须对UIIA
对象调用setupUi()
。你知道吗相关问题 更多 >
编程相关推荐