简体   繁体   English

AttributeError: 'Ui_MainWindow' object 没有属性 'close'

[英]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.

相关问题 Python AttributeError:“ UI_MainWindow”对象没有属性 - Python AttributeError: 'UI_MainWindow' object has no attribute AttributeError:'Ui_MainWindow'对象没有属性'setCentralWidget' - AttributeError: 'Ui_MainWindow' object has no attribute 'setCentralWidget' ui_mainwindow' 对象没有属性 'connect' - ui_mainwindow' object has no attribute 'connect' 参数 1 具有意外类型“Ui_mainWindow” - argument 1 has unexpected type 'Ui_mainWindow' Python AttributeError:NoneType对象没有属性'close' - Python AttributeError: NoneType object has no attribute 'close' AttributeError:'NoneType'对象没有属性'close' - AttributeError: 'NoneType' object has no attribute 'close' 调用类以在Window内构建QTreeWidget:参数1具有意外类型'Ui_MainWindow' - Calling a class to build a QTreeWidget within a Window: argument 1 has unexpected type 'Ui_MainWindow' Python-AttributeError:“ MyLogger”对象没有属性“ ui” - Python - AttributeError: 'MyLogger' object has no attribute 'ui' pyside,Qt Designer,封装的代码和AttributeError:“ MainWindow”对象没有属性“ QtGui” - pyside, Qt Designer, encapsulated code, and AttributeError: 'MainWindow' object has no attribute 'QtGui' Windows下的python 2.7:无法导入ui_mainwindow - python 2.7 under windows: cannot import ui_mainwindow
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM