Python tkinter: input not equal to answer? -
i have code using tkinter
, python
, when answer correctly, says answer wrong:
self.whatword = stringvar() self.missingwordprompt = entry(root, textvariable=self.whatword) self.missingwordprompt.pack() #self.missingwordprompt.bind('<return>', self.checkword()) self.submitbutton = button(root, text='check answer', command=self.checkword) self.submitbutton.pack() '''self.answerlabel = label(root, textvariable=self.missingword) self.answerlabel.pack()''' self.answer = self.missingword.get() print(self.answer) def checkword(self): self.my_input = self.missingwordprompt.get() print(self.my_input) if str(self.answer).lower() == str(self.my_input).lower(): print('correct') else: print('wrong answer')
in console this:
missing word: football football wrong answer football wrong answer
you must operate stringvar
instance e.g.:
self.whatword = stringvar() self.missingwordprompt = entry(root, textvariable=self.whatword) self.missingwordprompt.pack() self.submitbutton = button(root, text='check answer', command=self.checkword) self.submitbutton.pack() def checkword(self): self.answer = self.missingword.get() self.my_input = self.whatword.get() print(self.answer, self.my_input) if str(self.answer).strip().lower() == self.my_input.strip().lower(): print('correct') else: print('wrong answer')
read this manual tkinter.entry()
Comments
Post a Comment