from tkinter import
new_window = Tk()
new_window.title("Writing speed")
new_window.geometry("700x600+300+50")
question = ["How are you",
"Are you ok",
"I am fine",
"Long time no see",
"Good bye"]
result = []
user_result = []
question_index = 0
def clear(event):
user_input.delete(0, END)
def skip():
global question_index
question_index += 1
label1.config(text=f"Please write the following words\n\n {question[question_index]}")
def delete():
user_input.delete(0, END)
def check():
get_input_from_user = user_input.get()
user_result.append(get_input_from_user)
user_input.delete(0, END)
skip()
label1 = Label(new_window, text="Please write the following words\n\n {}".format(question[question_index]), font=("Arial black", 20))
user_input = Entry(new_window, width=40, font=("Courier New", 20))
skip_button = Button(new_window, text="skip", command=skip, width=40, bg="light green")
check_button = Button(new_window, text="check", command=check, width=40, bg="light green")
delete_button = Button(new_window, text="Delete", fg="red", bg="yellow", command=delete)
user_input.insert(0, "Your text here")
user_input.bind("<Button-1>", clear)
label1.pack()
user_input.pack(padx=20, pady=20)
skip_button.pack(padx=20)
check_button.pack(padx=20, pady=20)
delete_button.pack()
delete_button.place(x=625, y=144)
new_window.mainloop()
question_index = 0
user_result_index = 0
print(user_result)
for i in range(5):
if user_result[user_result_index] == question[question_index]:
result.append("Correct")
question_index += 1
user_result_index += 1
else:
result.append("Incorrect")
question_index += 1
user_result_index += 1
print(result)
The output of the code is index range out of range if the user press the check button more than 5 time and how to prevent the user from press the the check button more than or equal to five time. Is there any solution to solve this problem cause I have try a lot of ways to solve it and I failed it.
Any comment is welcomed.