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.


    Textfield with ui

    Pythonista
    4
    19
    4228
    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.
    • cvp
      cvp @Python567 last edited by

      @Python567 try this and press enter at end of typing Test123

      import ui
      tf = ui.TextField()
      tf.name = 'example for @Python567'
      tf.frame = (0,0,300,32)
      tf.keyboard_type = ui.KEYBOARD_DECIMAL_PAD
      tf.text = ''
      def tf_action(sender):
      	if sender.text == "Test123":
      		print("Hello")
      tf.action = tf_action
      tf.present('sheet')
      tf.begin_editing()
      
      1 Reply Last reply Reply Quote 0
      • cvp
        cvp @Python567 last edited by

        @Python567 you can use also this

        tf.placeholder = 'Your own explanation'
        

        test it

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

          Oh thanks, i test it

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

            I have here a programm which can find out all prime numbers. But I have the Problem, that I only can print the result in the console. I write tf.text = Right but it don‘t works why? I get a error with strand int. But I don‘t know how to fix that.

            import ui
            
            dialog = ui.View()
            
            
            tf = ui.TextField()
            tf.name = 'Test'
            tf.frame = (50,50,1000,100)
            tf.keyboard_type = ui.KEYBOARD_DECIMAL_PAD
            tf.text = ''
            tf.placeholder = 'Gib was ein!'
            
            def primzahl():
              p = int(tf.text)
              i = 2
              istPrimzahl = True 
              teiler = 0
              
              while (i < p):
                if p % i == 0:
              			istPrimzahl = False
              			teiler = i 
              			break 
                i += 1
            			
              if istPrimzahl:
                	tf.text = 'Die Zahl', p , 'ist eine Primzahl.'
            			
              else:
                	print ("Die Zahl",p, "ist keine Primzahl, weil sie durch " , i , " teilbar ist.") 
                	
                	
            def tf_action(sender):
            	primzahl()
              
            
            
            tf.action = tf_action
            
            dialog.add_subview(tf)
            
            ebutton = ui.Button()
            
            ebutton.title = '='
            ebutton.frame = (50,200,1000,100)
            ebutton.background_color = "red"
            def ebutton_action(sender):
            	tf.text = "gedrückt!"
            	
            ebutton.action = ebutton_action
            
            menubutton = ui.ButtonItem()
            menubutton.title = 'fghjk'
            dialog.right_button_items = [menubutton]
            
            
            dialog.add_subview(ebutton)
            dialog.present('fullscreen')
            tf.begin_editing()
            #sheet
            cvp 1 Reply Last reply Reply Quote 0
            • cvp
              cvp @Python567 last edited by

              @Python567 try already with

                      tf.text = 'Die Zahl ' + str(p) + ' ist eine Primzahl.'
              
              1 Reply Last reply Reply Quote 0
              • Python567
                Python567 last edited by Python567

                No, thanks:)

                cvp 1 Reply Last reply Reply Quote 0
                • cvp
                  cvp @Python567 last edited by

                  @Python567 said:

                  No

                  Why no?

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

                    @cvp Sorry, I wanna write a first something else wich beginn with „no“. 😐

                    cvp 1 Reply Last reply Reply Quote 0
                    • cvp
                      cvp @Python567 last edited by

                      @Python567 no problem 😉

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

                        F-strings (tf.text = f'Die Zahl {p} ist eine Primzahl.') are a single instruction in Python bytecode.
                        This makes them faster and more efficient than legacy string formatting https://www.scivision.dev/python-f-string-speed
                        Improved readability is also a clear value.

                        1 Reply Last reply Reply Quote 1
                        • MrEVandQuestions
                          MrEVandQuestions @cvp last edited by

                          @cvp that code works cool but what if I want to use it without presenting, the keyboard shortcuts?

                          cvp 1 Reply Last reply Reply Quote 0
                          • cvp
                            cvp @MrEVandQuestions last edited by

                            @MrEVandQuestions said:

                            use it without presenting, the keyboard

                            Remove the line

                            tf.begin_editing()
                            
                            1 Reply Last reply Reply Quote 0
                            • MrEVandQuestions
                              MrEVandQuestions last edited by

                              OK. Thanks!

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