It is, that’s where the focus is and why the focus on button vis @stucork codes is lost. When the text_box becomes the focus, pressing Enter doesn’t do anything unless a code to proceed further is added.
We already understand when a component has the focus, the keyboard input goes to that component. The issue here is figuring out what to do with that keyboard input.
A textbox often uses the letter keystrokes to fill its content, but it may decide to refuse numbers or punctuation. It often uses the tab keystroke to tell its parent (usually the form) to set the focus to the next component, it may ignores the enter or other keystrokes.
You may want for enter to do something when the focus is in one textbox, and something different when it is in another textbox of the same form.
A textarea is very similar to a textbox, but it often does use enter to insert a newline character in its value. I have some apps with textareas were I leave the tab doing its tab job, which is sending the focus to the next control, other apps where the tab inserts a tab character in the text, and other apps where the tab executes a function that uses the text in the textarea.
The focus can also be in components that don’t accept text, like a button or a checkbox. They usually use the space to execute the command or toggle the value, but some developers like to use use the enter as well.
So when you say “Enter doesn’t do anything unless a code to proceed further is added”, that’s exactly what it is supposed to do.
You are in charge of controlling the user input. The difficult thing is being consistent across all the apps and making sure the final result is intuitive.
Thank you, @stefano.menci for your detailed, eye-opening explanation.
I did try and enabled the method to run further on pressing Enter but thought that the whole thing just involved more codes compared to just invoking ‘self.button_submit_click’ sans the ‘focus’ option. Of course, one could argue that the ‘submit_button_click’ method itself also entail more codes.