code: def keyPressEvent(self, event):
          
          key = event.key()
          if key not in (Qt.Key_Enter, Qt.Key_Return):
              self.code_editor.keyPressEvent(event)
              self.close()
          else:
              super(QMenuOnlyForEnter, self).keyPressEvent(event)
docs: Close the instance if key is not enter key.