As for PyQt to run the method when I press a keyboard key?

There is a class , how to define keystrokes for example (E) on the keyboard and run some method .
Here is the part class code :
import sys
from wikides import *
from wikicore import *
from PyQt5 import QtCore, QtGui, QtWidgets
class MyWin(QtWidgets.QMainWindow):
 def __init__(self, parent=None):
 QtWidgets.QWidget.__init__(self, parent)
 self.ui = Ui_MainWindow()
self.ui.setupUi(self)
 self.path = os.path.dirname(__file__)
 self.pathTemp = self.path +'/temp'
 # Click on the button. 
self.ui.pushButton.clicked.connect(self.WikiGo)

 def WikiGo(self):
 cmd = recToText()
self.showText(cmd)
 # ....... etc.
June 5th 19 at 21:18
2 answers
June 5th 19 at 21:20
Solution
Ha, just on this rake was:

Add method:

def keyPressEvent(self, e):

 if e.key() in [QtCore.Qt.Key_Enter, QtCore.Qt.Key_Return]:
self.WikiGo()
else:
 super(MyWindow, self).keyPressEvent(e)


I have a class inherited from Ui_MainWindow, so there are options...
June 5th 19 at 21:22
Try to class MyWin add method:
def keyPressEvent(self, e):
 if e.key() == QtCore.Qt.Key_Q:
 self.run_me()

Written for the keys Q. find E (~), although this is not certain.

Find more questions by tags PyQtPython