omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    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.


    Text field keyboard

    Pythonista
    3
    12
    6023
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • donnieh
      donnieh last edited by

      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()
      
      1 Reply Last reply Reply Quote 0
      • omz
        omz last edited by

        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

        1 Reply Last reply Reply Quote 0
        • donnieh
          donnieh last edited by

          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...

          1 Reply Last reply Reply Quote 0
          • omz
            omz last edited by

            Are you running this on an iPhone or an iPad? Certain types of keyboard are only available on the iPhone...

            1 Reply Last reply Reply Quote 0
            • donnieh
              donnieh last edited by

              iPhone 6+

              1 Reply Last reply Reply Quote 0
              • donnieh
                donnieh last edited by

                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.

                1 Reply Last reply Reply Quote 0
                • omz
                  omz last edited by

                  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 True under 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 True as both the value of this (unused) variable and the label's alignment attribute. As I said, it happens to work in this particular case, but it wouldn't work with any other alignment than centered.

                  1 Reply Last reply Reply Quote 0
                  • donnieh
                    donnieh last edited by

                    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....

                    1 Reply Last reply Reply Quote 0
                    • omz
                      omz last edited by

                      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...

                      1 Reply Last reply Reply Quote 0
                      • donnieh
                        donnieh last edited by

                        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? )

                        1 Reply Last reply Reply Quote 0
                        • ccc
                          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)
                          
                          1 Reply Last reply Reply Quote 0
                          • donnieh
                            donnieh last edited by

                            Thank you! Much appreciated.

                            I am an electrical engineer trying to make it in a programming world :)

                            1 Reply Last reply Reply Quote 0
                            • First post
                              Last post
                            Powered by NodeBB Forums | Contributors