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.


    I’m not smart and need help

    Pythonista
    function variable
    2
    2
    1374
    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.
    • Checkmate
      Checkmate last edited by

      Can I change the value of a variable in a function called by a button?

      I tried it like this but it does not work sadly

      “ UnboundLocalError: local variable 'x' referenced before assignment”

      import ui 
      
      x = 100
      
      def action1(sender):
      	x -= 1
      
      
      view = ui.load_view()
      button = view["button1"]
      button.action = action1
      view.present('sheet')
      
      cvp 1 Reply Last reply Reply Quote 0
      • cvp
        cvp @Checkmate last edited by

        @Checkmate try this

        def action1(sender):
        	global x
        	x -= 1
        	sender.superview.name = str(x)
        
        1 Reply Last reply Reply Quote 2
        • First post
          Last post
        Powered by NodeBB Forums | Contributors