I’m following the Getting Started with Anvil Guest List Tutorial and ran into an error I can’t seem to correct:
TypeError: init() takes exactly 1 arguments (2 given)
at Form1, line 38
called from Form1, line 50
It happened when I changed my update_previous_signatures function. Here’s my code:
from anvil import *
import google.auth, google.drive, google.mail
from google.drive import app_files
# Import the RowTemplate class, which is
# defined by the RowTemplate form.
# We can use it like any other component.
from RowTemplate import RowTemplate
# Importing google.drive allows us to connect to
# our linked spreadsheet.
import google.drive
class Form1(Form1Template):
def btn_greet_click (self, sender, **event_args):
# This method is called when the button is clicked
user_name = self.txt_name.text
msg = self.txt_message.text
# Adding another row to a spreadsheet is simple
self.guest_sheet.add_row(name=user_name, message=msg)
self.update_previous_signatures()
def update_previous_signatures(self):
# First, we clear out all components from the LinearPanel,
# so it's completely empty.
self.first_visitors.clear()
# Now, we add a Label to the panel for each row
# in the spreadsheet.
#for row in self.guest_sheet.list_rows():
#row_label = Label(text=row["name"])
#self.first_visitors.add_component(row_label)
# Replacing the above for loop with the one below
# to allow instantaneous page updates
for row in self.guest_sheet.list_rows():
row_form = RowTemplate(row)
self.first_visitors.add_component(row_form)
def __init__(self, **properties):
# You must call self.init_components() before doing anything else in this function
self.init_components(**properties)
# Set "self.guest_sheet" to the first
# worksheet of your spreadsheet.
self.guest_sheet = google.drive.app_files.guest_book.worksheets[0]
# Start off by loading previous messages
self.update_previous_signatures()
def label_1_show (self, **event_args):
# This method is called when the Label is shown on the screen
pass
and the code from RowTemplate:
from anvil import *
import google.auth, google.drive, google.mail
from google.drive import app_files
class RowTemplate (RowTemplateTemplate):
def __init__(self, **properties):
# You must call self.init_components() before doing anything else in this function
self.init_components(**properties)
# Save a reference to the row object for later
self.sheet_row = row
# Display the text and message
self.lbl_name.text = row["name"]
self.lbl_message.text = row["message"]
Where am I adding that second argument? Or how can I accept two arguments?