I have the main file and my own function that I want to add. And he sends me the following error. The function path is fine and the function in the main file does work.
self.lbl = QLabel(self)
TypeError: arguments did not match any overloaded call:
QLabel(parent: QWidget = None, flags: Union[Qt.WindowFlags, Qt.WindowType] = Qt.WindowFlags()): argument 1 has unexpected type 'bool'
QLabel(str, parent: QWidget = None, flags: Union[Qt.WindowFlags, Qt.WindowType] = Qt.WindowFlags()): argument 1 has unexpected type 'bool'
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
import cv2
sys.path.append('./funciones')
from funciones import abrirArchivo as aF
from PIL import Image
if sys.platform.startswith('darwin'):
rsrcPath = ":/images/mac"
else:
rsrcPath = ":/images/win"
#clase heredada de QMAIN Window (constructor de ventanas)
class Ventana(QMainWindow,QWidget):
def __init__(self):#Metodo constructor de la clase
#super().__init__()
QMainWindow.__init__(self)
QTableWidget.__init__(self)
#QTableWidget.__init__(self)
self.showFullScreen() # Tamaño inicial de la ventana 800x500
# Barra de estado
self.statusBar().showMessage("Bienvenid@")
menu = self.menuBar() # Objeto menuBar
menu_archivo = menu.addMenu("&Archivo")# Menú padre
menu_editar = menu.addMenu("&Editar")# Menú padre
# Agregar un elemento acción al menu_archivo --- Abrir Archivo
menuArchivo_abrir = QAction("&Abrir",self)
menuArchivo_abrir.setStatusTip("Abrir Archivo")
menuArchivo_abrir.setShortcut("Ctrl+A")
menuArchivo_abrir.triggered.connect(aF._menuArchivo_abrir)
menu_archivo.addAction(menuArchivo_abrir)
#self.lbl.customContextMenuRequested.connect(self.menuContextual)
menuEditar_promedio = QAction("&Promedio", self)
menuEditar_promedio.setStatusTip("Promedio")
menuEditar_promedio.setShortcut("Ctrl+P")
menuEditar_promedio.triggered.connect(self._menuEditar_promedio)
menu_editar.addAction(menuEditar_promedio)
menuEditar_sobelX = QAction("&Sobel X", self)
menuEditar_sobelX.setStatusTip("Sobel X")
menuEditar_sobelX.setShortcut("Ctrl+SX")
menuEditar_sobelX.triggered.connect(self._menuEditar_SobelX)
menu_editar.addAction(menuEditar_sobelX)
# label
#self.lbl = QLabel(self)
#self.setContextMenuPolicy(Qt.ActionsContextMenu)
promedioAction = QAction("Promedio", self)
promedioAction.triggered.connect(self._menuEditar_promedio)
self.addAction(promedioAction)
#imagen = self._menuArchivo_abrir()
#sobelAction = QAction("Sobel X", self)
#sobelAction.triggered.connect(self._menuEditar_SobelX)
#self.addAction(sobelAction)
def menuContextual(self,point):
#mostrando el menu contextual
self.popMenuPromedio.exec(self.lbl.mapToGlobal(point))
def _menuEditar_promedio(self):
self.imagenOriginal = Image.open(self.nombreImagen)
print(self.imagenOriginal)
self.imagenPromedio = self.imagenOriginal
width, height = self.imagenOriginal.size
# [width,height]=image.shape
ipixel = self.imagenOriginal.load()
opixel = self.imagenPromedio.load()
for w in range(width):
for h in range(height):
if w > 0 and w < width - 1 and h > 0 and h < height - 1:
r1, g1, b1 = ipixel[w, h]
r2, g2, b2 = ipixel[w, h - 1]
r3, g3, b3 = ipixel[w, h + 1]
r4, g4, b4 = ipixel[w - 1, h]
r5, g5, b5 = ipixel[w - 1, h - 1]
r6, g6, b6 = ipixel[w - 1, h + 1]
r7, g7, b7 = ipixel[w + 1, h]
r8, g8, b8 = ipixel[w + 1, h - 1]
r9, g9, b9 = ipixel[w + 1, h + 1]
r, g, b = ((r1 + r2 + r3 + r4 + r5 + r6 + r7 + r8 + r9) / 9,
(g1 + g2 + g3 + g4 + g5 + g6 + g7 + g8 + g9) / 9,
(b1 + b2 + b3 + b4 + b5 + b6 + b7 + b8 + b9) / 9)
opixel[w, h] = (round(r), round(g), round(b), 255)
self.imagenPromedio.save('../a2.bmp')
self.imagenPromedio.show()
def _menuEditar_SobelX(self,imagen):
pass
if __name__ == '__main__':
app = QApplication(sys.argv)##instancia para iniciar la aplicación--obligatorio pasar los argumentos argv,esto es obligatorio
_ventana = Ventana()#creamos el objeto de la clase
_ventana.show()#mostrando la ventana
app.exec()#ejecutando la aplicación
My function
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
import cv2
def _menuArchivo_abrir(self):
# prueba de imagen
self.lbl = QLabel(self)
self.nombreImagen, _ = QFileDialog.getOpenFileName(self, "Open Image", "/home/", "Image Files (*.bmp)")
# self.cv2_imagenOriginal = cv2.imread(self.nombreImagen)
# print("nombre", self.cv2_imagenOriginal)
self.pixmap = QPixmap(self.nombreImagen)
self.lbl.setPixmap(self.pixmap)
self.lbl.resize(800, 600)
# self.lbl.
self.lbl.show()
#return self.nombreImagen