Find X and Y Coordinates with PyQt5 Python

-2

I want to find the x and y coordinates when I click on the photo. There is no error. It says "Process finished with exit code -1073740791 (0xC0000409)" Someone can help me? If you know the true way, I will write my code from the beginning.

Here is my code.

from PyQt5 import QtGui, QtWidgets
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QPushButton, QFileDialog, QLabel, QTextEdit, \
    QHBoxLayout, QCheckBox, QLineEdit, QGraphicsView
from PySide2 import QtCore
import sys
from PyQt5.QtGui import QPixmap


class Window(QWidget):
    def __init__(self):
        super().__init__()
        self.title = "PyQt5 Open File"
        self.top = 200
        self.left = 500
        self.width = 400
        self.height = 300
        self.InitWindow()

    def InitWindow(self):
        self.setWindowTitle(self.title)
        self.setGeometry(self.left, self.top, self.width, self.height)

        vbox = QVBoxLayout()
        hbox = QHBoxLayout()

        self.btn_pix_find = QtWidgets.QCheckBox("Find Point", self)
        self.pointInfo = QtWidgets.QLineEdit(self)
        self.pointInfo.setReadOnly(True)
        self.btn1 = QPushButton("Open Image")
        self.btn1.clicked.connect(self.getImage)

        vbox.addWidget(self.btn1)
        vbox.addWidget(self.btn_pix_find)
        vbox.addWidget(self.pointInfo)

        self.label = QLabel("")
        hbox.addWidget(self.label)
        vbox.addLayout(hbox)
        self.setLayout(vbox)
        self.show()

    def getImage(self):
        fname = QFileDialog.getOpenFileName(self, "Open file", "c:\\", "Image files (*.jpg *.gif)")
        imagePath = fname[0]
        pixmap = QPixmap(imagePath)
        self.label.setPixmap(QPixmap(pixmap))
        self.resize(pixmap.width(), pixmap.height())

    def mousePressEvent(self, event):
        if self.label.isEnabled():
            self.photo_clicked.emit(QtCore.QPoint(event.pos()))
        super(View, self).mousePressEvent(event)


    def photo_clicked(self, pos):
        if self.btn_pix_find.isChecked():
            self.pointInfo.setText('%d, %d' % (pos.x(), pos.y()))


App = QApplication(sys.argv)
window = Window()
sys.exit(App.exec())

I think problem is mousePressEvent someone can help me ?

python
pyqt5
asked on Stack Overflow Mar 19, 2020 by miracdogan

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0