Here's the sample how to use Tab or Enter key on HW keyboard to switch between text fields ...
import ui
_COUNT = 5
class TextFields(ui.View):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self._current_text_field = None
self._next_text_field = None
self._fields = [
ui.TextField(
frame=(12, 12 + (44 + 12) * i, self.bounds.size.width - 12, 44), flex='W',
bordered=True, delegate=self,
placeholder=f'Index {i}, next index {self._next_field_index(i)}'
)
for i in range(_COUNT)
]
for x in self._fields:
self.add_subview(x)
@staticmethod
def _next_field_index(index):
return index - 1 if index > 0 else _COUNT - 1
def textfield_should_begin_editing(self, textfield):
if not self._next_text_field:
return True
# Tricky part - if you do omit second part of this condition, iOS will INSERT
# tab character into your text field instead of switching to another text field.
# Basically this method should return True for text field you would like to switch
# to AND True for the current text field. Otherwise Tab character will be inserted
# as mentioned.
#
# Try it, remove `or ...` and you'll see how it behaves.
return textfield is self._next_text_field or textfield is self._current_text_field
def textfield_did_begin_editing(self, textfield):
self._next_text_field = self._fields[self._next_field_index(self._fields.index(textfield))]
self._current_text_field = textfield
def textfield_should_return(self, textfield):
self._next_text_field.begin_editing()
return True
v = TextFields(frame=(0, 0, 500, 500), background_color='white')
v.present('sheet')
... please, don't forget what @JonB wrote - Pythonista "just" wraps iOS components. If you're lost, consult UIKit reference.