python gui generate math equation
Posted
by
Nero Dietrich
on Stack Overflow
See other posts from Stack Overflow
or by Nero Dietrich
Published on 2012-10-13T21:34:18Z
Indexed on
2012/10/13
21:36 UTC
Read the original article
Hit count: 263
I have a homework question for one specific item with python GUIs.
My goal is to create a GUI that asks a random mathematical equation and if the equation is evaluated correctly, then I will receive a message stating that it is correct.
My main problem is finding out where to place my statements so that they show up in the labels; I have 1 textbox which generates the random equation, the next textbox is blank for me to enter the solution, and then an "Enter" button at the end to evaluate my solution.
It looks like this: [randomly generated equation][Empty space to enter solution] [ENTER]
I've managed to get the layout and the evaluate parameters, but I don't know where to go from here.
This is my code so far:
class Equation(Frame):
def __init__(self,parent=None):
Frame.__init__(self, parent)
self.pack()
Equation.make_widgets(self)
Equation.new_problem(self)
def make_widgets(self):
Label(self).grid(row=0, column=1)
ent = Entry(self)
ent.grid(row=0, column=1)
Label(self).grid(row=0, column=2)
ent = Entry(self)
ent.grid(row=0, column=2)
Button(self, text='Enter', command=self.evaluate).grid(row=0, column=3)
def new_problem(self):
pass
def evaluate(self):
result = eval(self.get())
self.delete(0, END)
self.insert(END, result)
print('Correct')
© Stack Overflow or respective owner