import sys from PyQt5 import QtCore, QtWidgets from PyQt5.QtWidgets import QApplication class Example(QtWidgets.QWidget): def __init__(self): super(Example, self).__init__() self.setGeometry(300, 300, 250, 150) self.show() def keyPressEvent(self, event): if event.key() == QtCore.Qt.Key_Q: print("Button pressed") self.deleteLater() elif event.key() == QtCore.Qt.Key_Enter: self.proceed() event.accept() def proceed(self): print("Call Enter Key") def main(): app = QApplication(sys.argv) ex = Example() sys.exit(app.exec_()) if __name__ == '__main__': main()