简体   繁体   English

尽管编写了 Python 函数,但它仍然缺少必需的参数

[英]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)

There is a mismatch between the argument list in the function called by this lambda function (6 arguments):lambda函数调用的函数中的参数列表之间存在不匹配(6 个参数):

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

and the function definition (7 arguments):和函数定义(7 个参数):

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

You skipped over the choicer argument.您跳过了选择choicer参数。 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.注意:如果没有你的其余代码,我不知道如何解释Question对象——它是一个模块,以某种方式引用本地文件范围,还是一个类。 So I assumed that Question.Checkanswer refers to the given function Checkanswer .所以我假设Question.Checkanswer指的是给定的函数Checkanswer

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 尽管代码能够工作,但 python 中缺少所需的位置参数 - Missing required positional argument in python despite code being able to work python 嵌套 function,缺少 1 个必需的位置参数 - python nested function, missing 1 required positional argument 在函数调用 Python 中缺少必需的潜在参数 - Missing required potential argument in function call Python 函数缺少1个必需的位置参数 - Function missing 1 required positional argument Python 使用 lamda function 错误缺少 1 个必需的位置参数:“事件” - Python using lamda function error missing 1 required positional argument: 'event' Python 3异常:TypeError:函数缺少1个必需的位置参数:'words' - Python 3 Exception: TypeError: function missing 1 required positional argument: 'words' 使用python定义超级简单函数,但“缺少1个必需的位置参数” - Defining super easy function with python but “missing 1 required positional argument” TypeError:函数缺少1个必需的位置参数:“ path”烧瓶Python - TypeError: function missing 1 required positional argument: 'path' Flask Python Python Pandas:用户定义的 function 缺少 1 个必需的位置参数 - Python Pandas: User defined function missing 1 required positional argument 缺少1个必需的位置参数-Python - Missing 1 required positional argument - Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM