<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def keyPressEvent(self, event):

 """Close the instance if key is not enter key."""

        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)