How to set the focus on a TextField?
Hi, is there any way to set the focus on input elements in UI Views? I have created a view containing a TextField and a WebView. I'd like to enter commands in the TextField with a Bluetooth keyboard and show the results of these commands in the WebView. It is quite annoying that whenever I hit the return key I need to use my finger to set the focus to the TextField again. Please, how can I do this automatically?
ccc last edited by
Sadly, the Tab key does not work, at least not in a Pythonista app.
Hmm, good idea, but that doesn't work. I was just wondering, because in console mode the cursor stays in the input field after pressing enter, allowing for continuous typing without having to take my hands away from the keyboard. It would be nice if ui.TextField could show the same behaviour.
Omega0 last edited by
You could use
TextField.begin_editing()if that's what you're looking for.
In the delegate for your textfield, after you do whatever it is that hitting the enter key currently does put
textfield.begin_editing()to return focus to the TextField.
Thank you very much! The problem was that I had copied the delegate example for the TextField from the documentation, but overlooked that it contains a call to
textfield_should_returndelegate method. Now that I have removed the line it works!
I'm glad that works for him, but for me the original problem remains: How to I set the focus to a TextField or TextView when loading a sheet?
omz last edited by
It works. I don't know what I was thinking before.