Text field keyboard
I have tried the code below to change the keyboard type, but no luck. What is the right way to do this?
import ui v = ui.View() tf = ui.TextField() tf.keyboard_type = DECIMAL=True v.add_subview(tf) v.present()
Try something like
tf.keyboard_type = ui.KEYBOARD_DECIMAL_PAD. The available keyboard types are documented here: http://omz-software.com/pythonista/docs/ios/ui.html#keyboard-type
Still not working. I guess I am not understanding the syntax structure to change the key board. With both methods above it runs without error, but no change in keyboard...
Are you running this on an iPhone or an iPad? Certain types of keyboard are only available on the iPhone...
For example I have done this and it works for text alignment:
label1.alignment = ALIGN_CENTER = TRUE
even though it is not the best way to do it.
So I figure that
tf.keyboard_type = DECIMAL = True
would work but it doesn't.
Then your solution of
tf.keyboard_type = ui.KEYBOARD_DECIMAL_PAD
looked promising but didn't work either.
I am on an iPhone 6+ and started a new script with the code up top to be sure I wasn't doing anything to keep the keyboard from changing. I am hoping to see an example of the keyboard changing at all. It seems it wont respond to any requests.
Could you show your entire code? I just tried the following minimal example on an iPhone 6, and it worked just fine:
import ui tf = ui.TextField() tf.keyboard_type = ui.KEYBOARD_DECIMAL_PAD tf.present()
Your text alignment code basically just works "by accident". The alignment constants are integers, and centered happens to be defined as
1, which is equivalent to
Trueunder some circumstances, but this isn't the right way to do it. What you're doing is basically to create a new local variable (
ALIGN_CENTER) and assign
Trueas both the value of this (unused) variable and the label's
alignmentattribute. As I said, it happens to work in this particular case, but it wouldn't work with any other alignment than centered.
I entered your latest code in a new script on my 6+ (running iOS 8.1.3). See screen shot:
https://dl.dropboxusercontent.com/u/47376215/Photo Mar 03%2C 8 30 38 AM.png
Here is the keyboard:
https://dl.dropboxusercontent.com/u/47376215/Photo Mar 03%2C 8 31 05 AM.png
P.S. thanks for the label alignment clarification....
Hmmm, okay, I'm sorry then. This might be something I fixed in 1.6 (beta); from the screenshot, it looks like you're running 1.5...
Wait a minute..... I cleared Pythonista from the iOS multitasking menu (double click home button) and re-ran the script and it works now....
(yes I am running the latest non beta version)
This happened with the label border clipping issue too. When I cleared the app from multitasking and reopened it my label corner radius clipped properly.
I hope this discussion was worth your time for debugging the next version. I really do appreciate your support as I learn Python.
( by the way, how would you recommend in an example I center align label text in contrast to my bad example? )
ccc last edited by
import ui w,h = ui.get_screen_size() tf = ui.TextField() tf.frame = (0, 50, w, 25) tf.keyboard_type = ui.KEYBOARD_DECIMAL_PAD lbl = ui.Label() lbl.frame = (0, 100, w, 25) lbl.border_width = 1 lbl.bg_color = 'white' lbl.alignment = ui.ALIGN_CENTER lbl.text = 'Center aligned label' v = ui.View() v.add_subview(tf) v.add_subview(lbl) v.present() v.wait_modal() print(tf.text)
Thank you! Much appreciated.
I am an electrical engineer trying to make it in a programming world :)