In my app, users only enter numbers. Change keyboard to numeral-friendly?
Hi all. Using pythonista on iOS. I want to help my daughter to make a super simple program to quiz her on multiplication tables. Since she's just learning python, this will be the bare bones, 15 or 20 line python script.
BUT, I realize that when we run the app, the input() command will cause the iPad to invoke the normal Pythonista keyboard. And in our app, when a user enters the answers to the questions, the user is asked to only enter numbers. they would pretty much be typing: 64 <return> 12 <return> 72 <return>
... But that standard iPad keyboard has the numerals positioned where you must press an additional key to switch to access the actual numbers. Ug. In practice, that means the user would have to type that extra "switch to numerals" each and every time they go to type in the next answer.
Is there a way I can fairly simply tell python/pythonista to invoke a keyboard that has numerals already pressable without pressing the additional key? But ideally not adding a large extra chunk of code to the app to totally build a GUI?
Whatever your simplest recommendation is, would be appreciated! even if it's a non-code suggestion like some third party keyboard I could download to the iPad :)
[[embarrassed that just the other day a similar question was posted. At the link here (but his is different in that he is building a GUI I believe.): https://forum.omz-software.com/topic/4930/use-the-numeric-keyboard-easily ]]
Create a my_input.py with
import ui def my_input(title): tf = ui.TextField() tf.name = title tf.text = '' tf.keyboard_type = ui.KEYBOARD_DECIMAL_PAD def tf_action(sender): sender.close() tf.action = tf_action tf.present('sheet',hide_title_bar=False) tf.begin_editing() tf.wait_modal() return tf.text
And your daughter may use it with
from my_input import my_input x = my_input('test') print(x)
ok, extended keyboard maybe went away in ios10..
@cvp Heyyy! That is very appreciated! So you pretty much showed me that I can avoid being afraid of the "ui" stuff. :) Thanks! ... I was in a hurry, so I only did one fast test of your method, and it works, that is exciting. But, I need to learn more about this. Because, for example, I noticed that the input text label appears on the screen, but on the ipad I have to tap on the input label if I want the keyboard to appear. Do you know a way to tell the app to "focus" on that input element, so that the keyboard immediately appears?
(Maybe I will see this problem go away when I actually build this function into our app.)
Anyway, this is cool, thank you again!
is supposed to focus the textfield, however, you might need to add a small delay after presenting, before this approach works.
Great. huge thanks for this. Someday I will have all these methods in my mind and I can stop feeling "on the outer edges" of them...
now also, I see I didn't need any delay. the flaw was that somehow the code that I copied into my app was not the full code that appears above. what I have re-copied works great. thanks.
@estephan500 Mea culpa. I had put some code without the tf.begin_editing and some minutes after I have modified it to add this line...Thus, if you have copied just between both, you got the first code. Sorry
I'm the guy who asked https://forum.omz-software.com/topic/4930/use-the-numeric-keyboard-easily
I have posted there how to change the type of keyboard using the UI Designer. It's super easy (once you know how to do it. I had to ask Ole).
I hope it helps.