Always try to work from Python entirely with any Javascript integration, your life will be much easier if it works. Only go out to Javascript functions if absolutely needed.
Here’s a clone that shows the basic example you were trying to run, but done entirely in Python and with an Anvil canvas component instead of a canvas hardcoded into the HTML template: Anvil | Login