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