2

una pregunta sencilla estoy tratando de detectar la tecla enter de mi teclado al presionarla pero no funciona. este es el codigo que utilizo:

import sys
from PyQt5.QtWidgets import QMainWindow, QApplication
from PyQt5 import QtCore
from PyQt5 import Qt


class Principal(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)


    def keyPressEvent(self,event):
        if event.key() == QtCore.Qt.Key_Enter:
            print("pressed")
        event.accept()



app = QApplication([])
p = Principal()
p.show()
app.exec_()
0

1 respuesta 1

1

QtCore.Qt.Key_Enter hace referencia a la tecla INTRO/ENTER del teclado numérico por norma general, debes usar en su lugar QtCore.Qt.Key_Return:

def keyPressEvent(self, event):
    if event.key() == QtCore.Qt.Key_Return:
        ...

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.