1

The specific error is:

_getandcreate() missing 5 required positional arguments: '_get_userpass', '_createuser', 't', 'username', and 'password'

Problematic subroutine:

def create_regwindow(self):
    t = tk.Toplevel(self)
    t.wm_title("Register")
    t.entry_user = tk.Entry(t)
    t.entry_pass = tk.Entry(t, show="*")
    t.title = tk.Label(t, text="Enter your new username and password below")
    t.field_user = tk.Label(t, text="Username")
    t.field_pass = tk.Label(t, text="Password")
    t.regbutton = tk.Button(t, text="Create Account", command=self._getandcreate) <-- HERE
    t.title.grid(row=0, sticky=tk.E)
    t.title.grid(row=0, column=1)
    t.field_user.grid(row=1, sticky=tk.E)
    t.field_pass.grid(row=2, sticky=tk.E)
    t.entry_user.grid(row=1, column=1)
    t.entry_pass.grid(row=2, column=1)
    t.regbutton.grid(row=3, column=1)

And the actual subroutine here:

def _getandcreate(self, _get_userpass, _createuser, t, username, password):
    _get_userpass(t)
    _createuser(username, password)

I need them variables to be passed into the command in the first block of code (labelled HERE), however, when I do this, I need to put these variables into a part of my code higher up (within init, whole code at bottom) - causing the issue of them not being defined.

I'm slightly confused. The purpose is, when the user clicks "Create Account", the data the user entered is taken and added to my database.

1 Answer 1

1

The callback system cannot know all your arguments. You could wrap your call in a lambda

t.regbutton = tk.Button(t, text="Create Account", command=self._getandcreate)

would become

t.regbutton = tk.Button(t, text="Create Account", command=lambda : self._getandcreate(t,<needed args>))

But there's much better to do here since you only deal with object members (methods or data).

Declare the _getandcreate and _get_userpass methods like this:

def _getandcreate(self):
    username, password = self._get_userpass()
    self._createuser(username, password)

def _get_userpass(self):
    t = self.__toplevel
    username = t.entry_user.get()
    password = t.entry_pass.get()
    return username, password

and set self.__toplevel in create_regwindow:

def create_regwindow(self):
    t = tk.Toplevel(self)
    self.__toplevel = t
Sign up to request clarification or add additional context in comments.

1 Comment

see my answer: you have to change get_userpass too. remove t parameter.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.