jeudi 30 avril 2020

Error in my Random Math GUI, answer.get() is not working properly

I am trying to do A Math Quiz game, for kids. This consists in a GUI that shows the random math question and the user needs to answer and press the button to enter. But, there is an error if you run it. In the part of getting the answer that the User has input, it doesn't work. So, I have tried every possible way to make it work, but nothing has worked for me. I hope someone can solve my problem. And a bonus if you are feeling extra generous would be if you could add and make work what I have in brackets for when the user has ran out of tries and mistakes.

from tkinter import *
import random
import time
import os


mathWindow = Tk()
mathWindow.title("RandomMath - SLSinfinity")

data=[]
print("----- RandomMath ----- \nBy SLSinfinity in 2020")

def file():

    file = open("RandomMathGUIScoreData.txt","a+")
    file.write(str(data))
    file.write("\n")
    file.close()
    f = open("RandomMathGUIScoreData.txt","r")
    print("\nCongratulations on your score!")


marks = 0
runs = 20
counter = 3  


def ifelse():

    if result == maths:
        string_to_display = "Well Done you got it Correct ✓"
        marks = marks + 1


    else:
        string_to_display = "Oh, you got it incorrect ✕"
        counter = counter - 1

    label2 = Label(mathWindow)
    label2["text"] = string_to_display
    label2.grid(row=1, column=1)

def something():
    result == answer.get()
    ifelse()


print("\nREMEMBER: (*) this is equal to this (x) multiply")
def Questions():
    operator = ["+","*"]
    operation = random.choice(operator)
    num1 = random.randint(0,10)
    num2 = random.randint(0,10)
    maths = str(num1) + operation + str(num2)
    question = Label(mathWindow, text=str(num1) + " " + operation + " " + str(num2) + " = ")

    answer = Entry(mathWindow)
    answer.grid(row=0, column=1)

    button1 = Button(mathWindow, text="Click here to submit answer", command = something)



    #.grid
    question.grid(row=0, column=0)

    button1.grid(row=1, column=0)


while runs > 0 and counter > 0:
    Questions()

    runs = runs - 1

#   elif counter == 0 or runs == 0:
#        repeat = input("You have zero chances or runs left. Do you want to continue? y/n : ")
#        if repeat == "y":
#            data.append(name)
#            data.append(marks)
#            file()
#            print(str(name) + " scored: " + str(marks))
#            marks = 0
#            counter = 3
#            runs=20
#            True
#        else:
#            False


 #  button2 = Button(mathWindow, text="Next", command = #)

   #button2.grid(row=1, column=2)

mathWindow.mainloop()



Aucun commentaire:

Enregistrer un commentaire