(I'm new to programming in general)
I created a program in python without an interface and part of it used a raw_input to get a users answer and compare with a stored answer.
This was in a loop that limited the number of attempts the user could have.
This worked because every time the program looped round to the input the user could change there answer from whatever they had before.
however when I tried to write this with a tkinter interface I used the EntryWidget.get() function, this seems to automatically get what ever is in the entrywidget without allowing the user to change this.
How can I get the program to allow the user to change there answer before the loop continues?
I tried to create a small program that illastrates the problem here
from Tkinter import *
returned_values = {}
class App:
def __init__(self,master):
frame = Frame(master)
frame.grid()
self.Answer_entry = Entry(master)
self.Answer_entry.grid(row = 0, column = 1, sticky=W)
User_Answer=self.Answer_entry.get()
self.exampleAnswer(master)
def exampleAnswer(self,master):
Answer = 'exampleAnswer'
self.CheckAnswerButton = Button(master, text="Check Answer", command=lambda: self.Check_Answer(Answer))
self.CheckAnswerButton.grid(row = 1, column = 3, sticky = S)
# answer defined in seperate function as it would be in prog
def Check_Answer(self,Answer):
attempts = 0 #sets the attempts = to 0 to start the loop
while 1: #starts infinite loop that will stop when break point hit
User_answer= self.Answer_entry.get()#gets users Answer entry
print User_answer
if User_answer != Answer: #checks if the user answer = the stored answer
if attempts >= 10:
returned_values['attempts'] = attempts
break #breaks the loop if the user has had 10 attempts
else:
attempts += 1 #adds one to attempts and repeats the loop
else: #only reaches this if there input is correct
returned_values['attempts'] = attempts #global variable ti give other functions access
break #breaks the loop
root = Tk()
app = App(root)
root.mainloop()