bruhbruh
bruhbruh

Reputation: 27

Python function keeps missing required argument, despite being written

I am trying to have a button pass a function, and have put in the variables that will be used (to avoid globals), however, I keep getting the error that I am missing a positional argument, despite the fact that I have already written it.

def ShowQuestion(quiz, instance, questionsAnswered, questionsdone, question, user_answer, check_answer, data):

    user_answer.focus_set()
    if instance == 0:

        question_set = random.sample(data,5)

    questionask = random.choice(question_set)

    current_question = questionask['question']

    question.config(text=current_question)

    question_set.remove(questionask)

    check_answer.config(command = lambda : Question.Checkanswer(quiz, instance, questionsAnswered, questionsdone, question, user_answer))
    check_answer.grid(row = 5, column = 3)


def Checkanswer(quiz, choicer, instance, questionsAnswered, questionsdone, question, user_answer):
    #print (choicer)
    questionsdone += 1
    if type(user_answer.get()) == str:
        user_answer = str(user_answer.get()).lower()
    else:
        user_answerwrong = user_answer.get()

    if user_answer in question_answer:
        correct_question +=1
    else:
        pass

    if questionsAnswered == 5:
        messagebox.showwarning("Final Score","Game Over \n Final Score: %s \n" %(self.user_score))
        quiz.destroy()
    else:
        instance +=1
        user_answer.delete(0, 'end')
        Question.ShowQuestion(quiz, instance, questionsAnswered, questionsdone, question, user_answer, check_answer, data)

Upvotes: 0

Views: 816

Answers (1)

Seb
Seb

Reputation: 4576

There is a mismatch between the argument list in the function called by this lambda function (6 arguments):

    check_answer.config(command = lambda : Question.Checkanswer(quiz, instance, questionsAnswered, questionsdone, question, user_answer))

and the function definition (7 arguments):

def Checkanswer(quiz, choicer, instance, questionsAnswered, questionsdone, question, user_answer):

You skipped over the choicer argument. Either pass it or remove the argument from the function definition (seeing as you don't use it in the function body).

Note: Without the rest of your code, I'm not sure how to interpret the Question object—whether it is a module, somehow referring to the local file scope, or a class. So I assumed that Question.Checkanswer refers to the given function Checkanswer.

Upvotes: 2

Related Questions