Welcome to the Forum @arneman44!
Passing arguments to your Form
@alcampopiano made a good suggestion regarding passing in the variable to the Form you are opening. As well as getting the variable out of the **properties
, you can also add your own parameters to __init__
, like so:
class Form2(Form2Template):
def __init__(self, your_own_parameter, **properties):
# Set Form properties and Data Bindings.
self.init_components(**properties)
# This is the bit you need to write
some_variable = your_own_parameter
Which you would use by doing this
from my_new_form import my_new_form
self.content_panel.clear()
new_form_instance=my_new_form('foo')
self.content_panel.add_component(new_form_instance)
Global variables
You can also store things in global variables that you can import from any Form. Create a Module named Global, then import that from both of your Forms:
from Global import my_variable
When you modify this variable in one Form, the modified version will be available in another Form (make sure you use a global my_variable
statement in any methods that modify it).
def button_1_click(self, **event_args):
"""This method is called when the button is clicked"""
global my_variable
my_variable = self.label_1.text
Here’s an example that uses a global variable to store search filters between two Forms:
https://anvil.works/build#clone:FDGKLWQEMXVSHXY5=BBQOKIWYCWLA6OBOKY4ES3PH