Custom Alert Window Output

As a NOOB, I am am trying to create a custom alert window where a user will enter API keys for an app integration.
I have created the window, but don’t know, how to get the string which the user enters.
Any help would be most welcome!

Alert Window:

Alert window form code:

class ApiKeyForm(ApiKeyFormTemplate):
  def __init__(self, **properties):
    # Set Form properties and Data Bindings.
    self.init_components(**properties)

    # Any code you write here will run before the form opens.
    
  def txtSecretKey_change(self, **event_args):
    """This method is called when the text in this text box is edited"""
    secretKey = self.txtSecretKey.text    
    pass

  def txtAccessKey_change(self, **event_args):
    """This method is called when the text in this text box is edited"""
    accessKey = self.txtAccessKey.text
    pass

from ...ApiKeyForm import ApiKeyForm

 result = alert(content=ApiKeyForm(), title="Enter API Key", large=True, buttons=[('OK',{'Secret Key': ApiKeyForm().txtSecretKey.text, 'Access': ApiKeyForm().txtAccessKey.text})])
print(result)

Result I am getting is {‘Secret Key’: ‘’, ‘Access’: ‘’}

If I remove the .text, then the result is
{‘Secret Key’: <anvil.TextBox object>, ‘Access’: <anvil.TextBox object>}

Hi hugh,

see below,

def txtSecretKey_change(self, sender,**event_args):
    """This method is called when the text in this text box is edited"""
    self.secretKey = sender.text    
    pass

  def txtAccessKey_change(self, sender,**event_args):
    """This method is called when the text in this text box is edited"""
    self.accessKey = sender.text
    pass
from ...ApiKeyForm import ApiKeyForm

apk=ApiKeyForm()
 result = alert(content=apk, title="Enter API Key", large=True, buttons=[('OK',True),('Cancel',False)])
if result:
  print(apk.secretKey,apk.accessKey)

1 Like

The answer from @meelvoorfer describes the correct way to do the job with Anvil without dependencies.

An alternative that doesn’t require the creation of a second form is using input_box.

1 Like

Thanks very much indeed. Super helpful.