Object-oriented GUI development in python
Hey guys, new programmer here. I have an assignment for class and I'm stuck... What I need to do is a create a GUI that gives someo开发者_运维问答ne a basic arithmetic problem in one box, asks the person to answer it, evaluates it, and tells you if you're right or wrong...
Basically, what I have is this:
class Lesson(Frame):
def __init__ (self, parent=None):
Frame.__init__(self, parent)
self.pack()
Lesson.make_widgets(self)
def make_widgets(self):
Label(self, text="").pack(side=TOP)
ent = Entry(self)
self.a = randrange(1,10)
self.b = randrange(1,10)
self.expr = choice(["+","-"])
ent.insert(END, str(self.a) + str(self.expr) + str(self.a))
I've broken this down into many little steps and basically, what I'm trying to do right now is insert a default random expression into the first entry widget. When I run this code, I just get a blank Label. Why is that? How can I put a something like "7+7" into the box? If you absolutely need background to the problem, it's question #3 on this link.
http://reed.cs.depaul.edu/lperkovic/csc242/homeworks/Homework8.html
-Thanks for all help in advance.
Do you want to change the Label or the contents of the Entry? I'll assume the latter. The short answer is
ent.delete(0, END)
ent.insert(END, 'stringy thing')
but nothing is going to change in the interface until the Tk() instance mainloop() method is called.
Change the
text=""
in the Label object instantiation to
text="Label Text"
or what ever you want to show as the label.
Next add
ent.pack()
after your ent.insert in your make_widgets method.
精彩评论