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.


    How i make UI buttons and link them?

    Pythonista
    4
    6
    3870
    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.
    • Abdalwahab
      Abdalwahab last edited by

      Hi I want to make a simple UI that change a label text to a text I input when I press a button

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

        Idk if this is the best solution, but u could do it this way:

        (0. create the button and the label with the ui designer...)

        1. click on the 'i' to edit the button
        2. set in the field "Action" a name (button1_Action, or what ever..)
        3. in the Code/py-File u have now to define the button and say, what it should do when clicked:
        def button1_Action(sender):
        	sender.superview['label1'].text = 'new Text'
        
        

        edit: I just saw that u want to set the text from a Text-input.
        in this case u have to expand it:
        instead of:

        def button1_Action(sender):
        	sender.superview['label1'].text = 'new Text'
        

        code this:

        sender.superview['label1'].text = sender sender.superview['textfield1'].text
        

        (or if u want to do it hard-coded: see post @ccc )

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

          some other resources for learning the ui module: the calculator example in the Examples/User Interface folder.
          Humberry's UI module tutorial

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

            import ui
            label = ui.Label(text='Label', text_color = 'red')
            
            def field_action(sender):
                label.text = sender.text
            
            field = ui.TextField(text='Field', action=field_action, enabled=False)
            field.y = label.y + label.height + 10
            
            def button_action(sender):
                field.enabled = not field.enabled
                    
            button = ui.Button(title='Button', action=button_action)
            button.y = field.y + field.height + 10
            
            view = ui.View()
            for subview in (label, field, button):
                view.add_subview(subview)
            view.present()
            
            1 Reply Last reply Reply Quote 1
            • ccc
              ccc last edited by

              A more responsive class-based approach...

              import ui
              
              class MyView(ui.View):
                  def __init__(self):
                      label = ui.Label(name='label', text='Label', text_color = 'red')
                      field = ui.TextField(name='field', text='Field', delegate=self, enabled=False)
                      field.y = label.y + label.height + 10
                      button = ui.Button(title='Disabled', action=self.action)
                      button.y = field.y + field.height + 10
                      for subview in (label, field, button):
                          self.add_subview(subview)
                      self.present()
              
                  def action(self, sender):
                      self['field'].enabled = not self['field'].enabled
                      sender.title = 'Enabled' if self['field'].enabled else 'Disabled'
              
                  def textfield_did_change(self, textfield):
                      self['label'].text = textfield.text
              
              MyView()
              
              1 Reply Last reply Reply Quote 1
              • ccc
                ccc last edited by

                import ui
                
                locked = ui.Image.named('iow:locked_32')
                unlocked = ui.Image.named('iow:unlocked_32')
                view = ui.View()
                field = ui.TextField(text='Field', enabled=False)
                view.add_subview(field)
                
                def action(sender):
                    field.enabled = not field.enabled
                    sender.image = unlocked if field.enabled else locked
                
                view.add_subview(ui.Button(action=action, image=locked, name='button'))
                view['button'].x = field.x + field.width + 10
                view.present()
                
                1 Reply Last reply Reply Quote 1
                • First post
                  Last post
                Powered by NodeBB Forums | Contributors