As the title says I'm stuggling with getting this to work. My code is not correct and I keep getting an error saying that basically everything in my function 'enter' is undefined.
My code:
from tkinter import Tk, Button, Label, Entry, END
from tkinter.messagebox import showinfo
import random
class Ed():
'helps teach kids simple addition and subtraction'
'''sets the problem in an (a operation b) setting
in entry box 1. Number cannot be negative'''
a = random.randrange(1,9) #first number
b = random.randrange(1,9) #second number
c = random.randrange(1,2) #set the operation
def enter():
'checks the answer in entry 2 if it is correct'
ans = eval(anwEnt.get())
pEnt.delete(0, END)
anwEnt.delete(0, END)
root = Tk()
# problem entry
pEnt= Entry(root)
pEnt.grid(row=1, column=1)
if c == 1:
pEnt.insert(END, '{} + {}'.format(a,b))
if c == 2 and a > b:
pEnt.insert(END, '{} - {}'.format(a,b))
if b > a and c == 2:
pEnt.insert(END, '{} - {}'.format(b,a))
# answer entry
anwEnt = Entry(root)
anwEnt.grid(row=2, column=1)
# Button
button = Button(root, text = 'Enter', command=enter)
button.grid(row=3, column=0, columnspan=2)
root.mainloop()
I know that I need to use init but I really am not sure how to. Any help will be greatly appreciated.
Thanks in advance