You can define macros - that means global available Python functions - in the onopen() action of the form, and then call it from any other action:
Example 5.7. Macro example
def mymakro(hk_this,v): hk_this.show_warningmessage("Displaying the text: "+v)
This can be called from a buttons onclick action: