Definining actions
Actions are defined using two options in the button widget, the action and action_key or action_keys. For each button you
want to perform an action, set action to a function you can pass through to the button, and set action_keys to the keys that will cause the action to be performed when that button is selected.
In the example below, the action_keys are set to the ENTER key on the numeric keypad and the ENTER key (carriage return) on the keyboard for both buttons. This won’t cause a conflict, because the button will only activate the action for the button that happens to be selected at the time.
app.widget("button", button_name="quick",
color="default_on_blue",
text="quick",
action=quick_output_panel, action_keys=["\n", "KEY_ENTER"],
x=1, y=1, height=5, width=13, selected=selection[0])
app.widget("button", button_name="brown",
color="default_on_blue", text="brown",
action=brown_output_panel, action_keys=["\n", "KEY_ENTER"],
x=1, y=7, height=5, width=13, selected=selection[1])
This is so that you can define common ways for the user to activate a button, without having to define a different control for each individual button.
See using_buttons.py for the full example referenced in this documentation.