Function Not Defined

My function is getting a not defined error.
Where can I find simple code samples for anvil, please?

image

hi @codeman and welcome to the forum,

Looks like you’re expecting output to be a function in the global namespace.

But output is an attribute of the the class Form1 and so you need to access it as an attribute.

self.output() is what you want here

self is an instance of Form1 and when you do self.output(), self will become the first argument to that function.

Thank you, it worked. But where can I find simple code samples for Anvil? I looked all through the documents and did not see anything like self.output(), in other compilers I use just output.(). When I mean code samples, I mean common differences from a regular Python compiler.

There should be plenty of examples in the learning centre:

When you say regular python - it’s worth noting that this is regular python. It’s just that Anvil’s design means that a class based object oriented model is favoured. If you’ve ever written a class based tkinter app, it will be a very similar experience.

1 Like

It’s worth noting that self. is not Anvil specific. Any Python code that uses classes uses the self. syntax, so maybe also look up some intro to classes tutorials for Python. The w3schools intro shows some examples: Python Classes

Where Anvil differs from straight Python is that you have some inherited methods (e.g. form_show) that are called in specific situations defined by Anvil.