Как сделать кнопку закрытия окна в pyside6?

Код:

import sys

from PySide6 import QtWidgets, QtCore
from icrawler.builtin import GoogleImageCrawler, GreedyImageCrawler

import design  
import error
status = True

class ExampleApp(QtWidgets.QMainWindow, design.Ui_MainWindow):
    def __init__(self):
        super().__init__()
        self.setupUi(self)  

        self.path.setReadOnly(True)
        self.path_3.setReadOnly(True)

        # Slide menu
        self.button_menu.clicked.connect(lambda: self.toggle_menu(140 ,True))
        # Scraping. Button start
        self.start_button.clicked.connect(lambda: self.web_parse())
        # Button path
        self.button_view.clicked.connect(lambda: self.browse_folder_web())
        self.button_view_3.clicked.connect(lambda: self.browse_folder_site())
        # QStackedWidget button
        self.button_web.clicked.connect(lambda: self.settings_web_scraping())
        self.button_site.clicked.connect(lambda:self.settings_site_scraping())
      
        

    def toggle_menu(self, maxWidth, enable): # Menu button
        if enable:
            # Get width
            width = self.left_menu.width()
            maxExtend = maxWidth
            standart = 50

            # Set max width
            if width == 50:
                widthExtended = maxExtend
            else:
                widthExtended = standart

            # Animation
            self.animation = QtCore.QPropertyAnimation(self.left_menu, b"minimumWidth")
            self.animation.setDuration(400)
            self.animation.setEndValue(widthExtended)
            self.animation.start()

    def web_parse(self): # Scraping google pictures
        global status
        try:
            if status:
                # Settings
                type = self.list_type.currentText().lower()
                size = self.list_size.currentText().lower()
                color = self.list_color.currentText().lower()
                try:
                    min_size = (int(self.min_size.text().lower().split('x')[0]),
                        int(self.min_size_3.text().lower().split('x')[1])
                        ) # Tuple of width and height
                except:
                    min_size = None
                try:
                    max_size = (int(self.max_size.text().lower().split('x')[0]),
                        int(self.max_size_3.text().lower().split('x')[0])
                        ) # Tuple of width and height
                except:
                    max_size = None
                count = int(self.count.text())
                keyword = self.keyword.text()
                path = self.path.text()
                filters = dict(
                type=type,
                color=color,
                size=size
                )
                crawler = GoogleImageCrawler(storage={'root_dir': fr'{path}'}, downloader_threads=10)


                crawler.crawl(
                    keyword=keyword,
                    max_num=count,
                    min_size=(int(min_size[0]), int(min_size[1])),
                    max_size=(int(max_size[0]), int(max_size[1])),
                    overwrite=True,
                    filters=filters,
                    file_idx_offset='auto'
                )
            else:
                url = self.url.text()
                count = int(self.count_3.text())
                try:
                    min_size = (int(self.min_size_3.text().lower().split('x')[0]),
                        int(self.min_size_3.text().lower().split('x')[1])
                        ) # Tuple of width and height
                except:
                    min_size = None
                try:
                    max_size = (int(self.max_size_3.text().lower().split('x')[0]),
                        int(self.max_size_3.text().lower().split('x')[0])
                        ) # Tuple of width and height
                except:
                    max_size = None
                path = self.path_3.text()
                greedy_crawler = GreedyImageCrawler(storage={'root_dir': fr'{path}'},downloader_threads=10)
                greedy_crawler.crawl(
                    domains=url,
                    max_num=count,
                    min_size=min_size,
                    max_size=max_size,
                    file_idx_offset='auto'
                    )

        except: # Open error window
            self.window = QtWidgets.QDialog()
            self.ui = error.Ui_Error()
            self.ui.setupUi(self.window)
            self.window.show()
            self.ui.button_ok_error.clicked.connect(self.window.close())


    def browse_folder_web(self):   # Set path in the field
        directory = QtWidgets.QFileDialog.getExistingDirectory(self, "Выберите папку")
        self.path.setText(directory)

    def browse_folder_site(self):  # Set path in the field
        directory = QtWidgets.QFileDialog.getExistingDirectory(self, "Выберите папку")
        self.path_3.setText(directory)

    def settings_web_scraping(self): # Set another QStackedWidget if button pressed
        global status
        self.center_body.setCurrentWidget(self.center_bodyPage1)
        status = True

    def settings_site_scraping(self):
        global status
        self.center_body.setCurrentWidget(self.page_2)
        status = False

def main():
    app = QtWidgets.QApplication(sys.argv) 
    window = ExampleApp()  
    window.show()  
    app.exec()  

if __name__ == '__main__':  
    main() 

В методе web_parse при except я открываю окно, где написано ошибка. В окне есть кнопка ok, которая должна закрывать его, но у меня выходит только ошибка, а окно моментально закрывается даже без нажатия на кнопку.

TypeError: 'PySide6.QtCore.QObject.connect' called with wrong argument types:
  PySide6.QtCore.QObject.connect(QPushButton, str, bool)
Supported signatures:
  PySide6.QtCore.QObject.connect(PySide6.QtCore.QObject, bytes, Callable, PySide6.QtCore.Qt.ConnectionType = PySide6.QtCore.Qt.ConnectionType.AutoConnection)
  PySide6.QtCore.QObject.connect(bytes, Callable, PySide6.QtCore.Qt.ConnectionType = PySide6.QtCore.Qt.ConnectionType.AutoConnection)
  PySide6.QtCore.QObject.connect(bytes, PySide6.QtCore.QObject, bytes, PySide6.QtCore.Qt.ConnectionType = PySide6.QtCore.Qt.ConnectionType.AutoConnection)
  PySide6.QtCore.QObject.connect(PySide6.QtCore.QObject, bytes, bytes, PySide6.QtCore.Qt.ConnectionType = PySide6.QtCore.Qt.ConnectionType.AutoConnection)
  PySide6.QtCore.QObject.connect(PySide6.QtCore.QObject, PySide6.QtCore.QMetaMethod, PySide6.QtCore.QObject, PySide6.QtCore.QMetaMethod, PySide6.QtCore.Qt.ConnectionType = PySide6.QtCore.Qt.ConnectionType.AutoConnection)       
  PySide6.QtCore.QObject.connect(PySide6.QtCore.QObject, bytes, PySide6.QtCore.QObject, bytes, PySide6.QtCore.Qt.ConnectionType = PySide6.QtCore.Qt.ConnectionType.AutoConnection)

Ответы (1 шт):

Автор решения: RuCat

Нужно использовать lambda функции. Вместо self.ui.button_ok_error.clicked.connect(self.window.close()) использовать self.ui.button_ok_error.clicked.connect(lambda: self.window.close()).

→ Ссылка