Im a beginner in python and my sister is learning her multiplication so I wanted to make a program that gives her random problems from 2 to 5. whenever i click the check button, nothing happens(its suppose to change the lblProblem stringvar to say right for 1 sec then switch to another problem). any help or beginner tips are useful. Thank you!
from tkinter import *
import random
import time
root = Tk()
title = Label(root, text="xX Multiplcation Xx", font=("Helvetica"))
global Num1
Num1 = random.randint(2, 5)
global Num2
Num2 = random.randint(2, 10)
def reset():
LblProblem.set(f"{Num1} x {Num2}")
LblProblem = StringVar()
LblProblem.set(f"{Num1} x {Num2}")
def AnswerCheck(Num1, Num2):
userGuess = int(Answer.get())
if userGuess == (Num1 * Num2):
LblProblem = "right!"
time.sleep(1)
Num1 = random.randint(2, 5)
Num2 = random.randint(2, 10)
reset()
elif userGuess > (Num1 * Num2):
LblProblem = "Lower"
time.sleep(1)
Num1 = random.randint(2, 5)
Num2 = random.randint(2, 10)
LblProblem.set(f"{Num1} x {Num2}")
elif userGuess < (Num1 * Num2):
LblProblem = "Higher"
time.sleep(1)
Num1 = random.randint(2, 5)
Num2 = random.randint(2, 10)
LblProblem.set(f"{Num1} x {Num2}")
else:
print("error")
#Main part
Problem = Label(root, textvariable=LblProblem, font=("Helvetica"))
Answer = Entry(root)
check = Button(root, text="Check", fg="green", command=lambda: AnswerCheck(Num1, Num2))
title.pack()
Problem.pack()
Answer.pack()
check.pack()
root.mainloop()