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?
textfield.end_editing()to hide the keyboard when you do not need it
textfield.keyboard_typeset to one of the following, experiment which is best for your use case:
@FDT, I do not fully understand your last question. Maybe if you share some (simplified) code?
I'd like to have the keyboard pop up as a numeric keyboard
If you really want a numeric keyboard only, see here
@mikael It would be great if you could show a little snippet of code showing the context of the methods.
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()