Flexform checkbox returns none

I’m trying to get the value of a check box in a flexform. I thought I might be having issues with it because I’m closing the form in a function that is called by a button so I tried adding it to the functions but that is not working either. Every time it returns None.

accepted = False
invertStatus = False
def acceptPressed(sender, args):
    global accepted
    global invertStatus
    accepted = True
    invertStatus = form.values.get("Invert")
    form.close()

def cancelPressed(sender, args):
    global accepted
    global invertStatus
    accepted = False
    invertStatus = form.values.get("Invert")
    form.close()

components = [Label("Invert, Accept, or Cancel"),
              CheckBox("Invert", "Invert"),
              Button("Accept", on_click=acceptPressed),
              Button("Cancel", on_click=cancelPressed)
              ]
form = FlexForm("Confirm Change", components)
form.show()

print(form.values.get("Invert"))

print("Is accepted?")
print(accepted)
print("Is Inverted?")
print(invertStatus)

Ok, I’ve read the docs a little closer and noticed that the default for button is get_values which actually SETS the values. So I changed the function to remove form.close() because get_values does that and get the value before setting the status. I also had to use (sender, e) which, I’ll be honest, have no idea what it is, where it comes from, or why it needs to be there. :stuck_out_tongue:

accepted = False
invertStatus = False
def acceptPressed(sender, e):
    global accepted
    global invertStatus
    accepted = True
    form.get_values(sender, e)
    invertStatus = form.values.get("invert")


def cancelPressed(sender, e):
    global accepted
    global invertStatus
    accepted = False
    form.get_values(sender, e)
    invertStatus = form.values.get("invert")


components = [Label("Invert, Accept, or Cancel"),
              CheckBox("invert", "Invert Rotation"),
              Button("Accept", on_click=acceptPressed),
              Button("Cancel", on_click=cancelPressed)
              ]
form = FlexForm("Confirm Change", components)
form.show()

print("Is accepted?")
print(accepted)
print("Is Inverted?")
print(invertStatus)
1 Like