Link from form "Home" to form "Form1"

Hi I am quite new to Anvil and python.
I would like to know how to connect two form together that is if I am on a form called “Home” how do I get that to link to (when pressed go to) a form called “Form1”?

Welcome to Anvil.

Place a Link component on your Home form.

In the “clicked” event (reached either by double clicking the link in the editor or clicking the arrow key next to the event in the IDE properties for the link).

In the link1_clicked() event code, enter :

open_form("Form1")

Do take the time to read the documentation and work through the examples. They are very good and will give you a solid understanding how Anvil works.

1 Like

Hi David. I did as you said but it says:
NameError: name ‘Form1’ is not defined at [Home, line 17](javascript:void(0))

What can I do to fix this

Hello. Do you have a form on the left named “Form1” ? If not you’ll need to rename things accordingly.

Yes I have it named “Form1”

Please share a clone of the app if possible. Click the :gear: icon and follow the instructions. Otherwise share more code please.

https://anvil.works/build#clone:M3RTR7Y7PRLDEMVC=NDENSNBW7NYYJBPR4QQOZZKQ

Hopefully this can help you in diagnosing my issue

open_form takes a string as its first argument.

open_form('Form1')

This will work.

I’m not sure I understand.

Wait I understand now, we need to put the apostrophe in. Thank you. This has helped

A string is anything in python surrounded in single or double (or triple) quotes. The “argument” is what gets passed to the function. In this case the function is open_form and the argument is 'Form2' (notice the single quotes).

Compare what I have written above to what is in your code. You will see that you are calling Form2 as a variable (which is not defined, hence the error). I have enclosed Form2 in single quotes, making it a string. That is what the function open_form takes inside its parentheses.

2 Likes