Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Control keyboard ui
-
Hi - I'm building a special calculator. I use textviews to enter and display data. I would like to have the keyboard disappear, after I press a UI button (my calculate button). When I enter data into a textview, the keyboard covers the lower half my calculator UI and it does not disappear, after I press the calculate button. Also, I'd like to have the keyboard pop up as a numeric keyboard, when I tap a textview., since I'm building calculators.
I use a buttons to call a functions. Do I have to make the keyboard control code part of the function(s) or should it be located at the end of the script?
Thanks,
Forrest
-
@FDT, use:
textfield.end_editing()
to hide the keyboard when you do not need ittextfield.keyboard_type
set to one of the following, experiment which is best for your use case:- ui.KEYBOARD_DECIMAL_PAD
- ui.KEYBOARD_NUMBERS
- ui.KEYBOARD_NUMBER_PAD
-
@FDT, I do not fully understand your last question. Maybe if you share some (simplified) code?
-
-
@mikael It would be great if you could show a little snippet of code showing the context of the methods.
-
@mikael said:
textfield.end_editing()
I got the textfield.end_editing() to work and it's a big help! The keyboard_type code has me stumped. I have googled it extensively and haven't found a syntax that works.
-
@FDT, mostly, do not google, but highlight the class name and select Help... from the popup options to see attributes like these.
Here’s a quick sample:
import ui v = ui.View() tf = ui.TextField( placeholder='First number', keyboard_type=ui.KEYBOARD_DECIMAL_PAD, width=200, height=40, center=v.bounds.center(), flex='RTBL', ) v.add_subview(tf) v.present()