-2
为什么这两个函数不工作?名称'xxx'未定义
class Window(QtGui.QMainWindow):
def __init__(self):
super(Window, self).__init__()
self.setGeometry(500, 150, 500, 600)
self.home()
def home(self):
btn_run = QtGui.QPushButton("Run", self)
btn_run.clicked.connect(self.run)
btn_run.resize(120, 40)
btn_run.move(220, 540)
self.show()
def view_splash(arg1):
label = QLabel("<font color=red size=10<b>" + n[arg1] + "</b></font>")
label.setWindowFlags(Qt.SplashScreen | Qt.WindowStaysOnTopHint)
label.show()
QtCore.QTimer.singleShot(10000, label.hide)
def run(self):
for i in range(len(lines)):
n = random.choice(words)
view_splash(0)
view_splash(1)
time.sleep(600)
我有一个错误:
view_splash(0)
NameError: name 'view_splash' is not defined
我做错了吗? 这应该如何?
好'行'没有被定义为...或'文字'...:/ – Idos
我还没有尝试过这个,但也许'this.view_splash(0)'会工作。 –
你应该修改如何处理Python中的类:https://docs.python.org/3/tutorial/classes.html – idjaw