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.


    Button thing?

    Pythonista
    2
    3
    1499
    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.
    • Bumbo Cactoni
      Bumbo Cactoni last edited by Bumbo Cactoni

      How would I create a button on-screen that changes color when you tap it? Like, a square that starts white with a black border then changes to a square that’s black with a white border?

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

        @Bumbo-Cactoni like this?

        import ui
        v = ui.View()
        v.background_color = 'gray'
        def tapped(sender):
        	sender.background_color = ['black','white'][sender.flag]
        	sender.border_color = ['black','white'][1-sender.flag]	
        	sender.flag = 1-sender.flag
        b = ui.Button()
        b.frame = (10,10,100,32)
        b.title = 'button'
        b.border_width = 1
        b.flag = 0
        b.action = tapped
        v.add_subview(b)
        tapped(b)
        v.present('fullscreen') 
        
        1 Reply Last reply Reply Quote 0
        • Bumbo Cactoni
          Bumbo Cactoni last edited by

          @cvp
          That was exactly what I needed!
          Thank you!

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