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.


    ui.view.close() not working as expected

    Pythonista
    2
    4
    646
    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.
    • peiriannydd
      peiriannydd last edited by peiriannydd

      I’m sorry if this has an obvious answer, but I am unable to get this to work. I want to use a custom close button but it doesn’t work for me. What am I missing? Thank you!

      ` import ui

      v = ui.View()

      b1 = ui.Button(title = "why doesn't this close button work?")
      b1.frame = (50,100,270,50)
      b1.background_color = '#d0d0d0'
      b1.action = v.close()

      v.add_subview(b1)
      v.present('fullscreen', hide_title_bar=True)```

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

        try v.close, not v.close()

        the first way is a function handle.
        the second way calls the function (which returns None).

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

          sorry, actions must accept one argument, sender. here are two options

          '''action must take one argument -- sender which will be the button.  a lambda will wrap this....'''
          b1.action = lambda sender: v.close()
          
          ''' alternatively, allow for other cleanup if needed'''
          def close_parent(sender):
             sender.superview.close()
          b1.action = close_parent
          
          1 Reply Last reply Reply Quote 0
          • peiriannydd
            peiriannydd last edited by

            Thank you JonB! I knew I must be missing something, and I never would have figured that out.

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