Forum Archive

I’m not smart and need help

Checkmate

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

@Checkmate try this

def action1(sender):
    global x
    x -= 1
    sender.superview.name = str(x)