Button wrong event
-
I want to click on the import button to open the image. How can I do this correctly in Python? Now my button is pressed by itself, the picture turns out to be opened, but the event does not work again.
To open a picture I have the following code
def display_image(): load_image = QLabel() image_name = QFileDialog.getOpenFileName(load_image, 'Open file', '\\Images', "Image Files (*.jpg *.gif *.bmp *.png)") loaded_image = QPixmap(image_name[0]) load_image.setPixmap(loaded_image) load_image.setScaledContents(True) return load_imageAnd, accordingly, such a function call
image_import_btn.clicked.connect(grid_image_detect.addWidget(display_image(), 0, 1)) image_import_btn.clicked.connect(grid_image_detect.addWidget(display_image(), 0, 2)) image_detect.setLayout(grid_image_detect)I tried to store the result in a variable
I've tried calling the function on click, but it doesn't work.image_import_btn.clicked.connect(display_image())Returns
Traceback (most recent call last):
File "main.py", line 117, in goto_image_obj_detect image_obj_detect()
File "main.py", line 1020, in image_obj_detect image_import_btn.clicked.connect(display_image())
TypeError: 'PySide6.QtCore.QObject.connect' called with wrong argument types:
PySide6.QtCore.QObject.connect(QPushButton, str, QLabel)
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) -
I want to click on the import button to open the image. How can I do this correctly in Python? Now my button is pressed by itself, the picture turns out to be opened, but the event does not work again.
To open a picture I have the following code
def display_image(): load_image = QLabel() image_name = QFileDialog.getOpenFileName(load_image, 'Open file', '\\Images', "Image Files (*.jpg *.gif *.bmp *.png)") loaded_image = QPixmap(image_name[0]) load_image.setPixmap(loaded_image) load_image.setScaledContents(True) return load_imageAnd, accordingly, such a function call
image_import_btn.clicked.connect(grid_image_detect.addWidget(display_image(), 0, 1)) image_import_btn.clicked.connect(grid_image_detect.addWidget(display_image(), 0, 2)) image_detect.setLayout(grid_image_detect)I tried to store the result in a variable
I've tried calling the function on click, but it doesn't work.image_import_btn.clicked.connect(display_image())Returns
Traceback (most recent call last):
File "main.py", line 117, in goto_image_obj_detect image_obj_detect()
File "main.py", line 1020, in image_obj_detect image_import_btn.clicked.connect(display_image())
TypeError: 'PySide6.QtCore.QObject.connect' called with wrong argument types:
PySide6.QtCore.QObject.connect(QPushButton, str, QLabel)
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)