[英]AttributeError: 'Ui_MainWindow' object has no attribute 'close'
So, I am making an application using pyqt5 I want to close the window when I click a button, For that, I wrote this:所以,我正在使用 pyqt5 制作应用程序,我想在单击按钮时关闭 window,为此,我写了这个:
self.login.clicked.connect(self.closewin)
and the close fuction is:关闭功能是:
def closewin(self):
self.close()
and I am getting this error我收到了这个错误
AttributeError: 'Ui_MainWindow' object has no attribute 'close'
what should I do now?我现在该怎么办?
Connect slots in MainWindow.__init__()
not in Ui_MainWindow.setupUi()
.连接MainWindow.__init__()
中而不是Ui_MainWindow.setupUi()
中的插槽。 MainWindow
is window class (put def closewin(self)
here), Ui_MainWindow
is helper class. MainWindow
是 window class(把def closewin(self)
放在这里), Ui_MainWindow
是助手 class。
ui = Ui_MainWindow()
ui.setupUi(self)
ui.login.clicked.connect(self.closewin)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.