Simple Tkinter problem

gmarkowsky at gmail.com gmarkowsky at gmail.com
Tue Nov 7 16:15:09 CET 2006


Here's my Tkinter class:

class TwoChoice:
    def __init__(self, master):

        frame = Frame(master)
        frame.pack()
        m = Label(root, text= maentry)
        m.pack()
        n = Label(root, text= fave)
        n.pack()

        self.button = Button(frame, text=home_team, command=
self.comm_1)
        self.button.pack(side=LEFT)

        self.hi_there = Button(frame, text=vis_team,
command=self.comm_2)
        self.hi_there.pack(side=LEFT)

    def comm_1(self):
        print home_team
        root.quit()

    def comm_2(self):
        print vis_team
        root.quit()

I call it by

root = Tk()
gui= TwoChoice(root)
root.mainloop()

The next time I call it I want to just run the same thing but with
different values for the variables. Instead it gives me like two copies
of the widget.

Greg

Neil Cerutti wrote:
> On 2006-11-07, gmarkowsky at gmail.com <gmarkowsky at gmail.com> wrote:
> > I'm trying to write a GUI that will put up multiple widgets in
> > succession. My problem is that each widget also contains the
> > previous widgets when they pop up. How do I reinitialize the
> > widget each time so that it doesn't contain earlier ones?
>
> Show your code.
>
> > Actually, another question I have is, is there a way to set
> > python so that it will assume any undefined variable is 0 or
> > ''? That is, I have several statements like "If k > 0 then so
> > and so" and I would like it to assume k=0 unless I tell it
> > otherwise. I've just been defining k=0 at the start of the
> > program but it seems there should be a better way.
>
> The best way to do it is to never use undefined names.
> 
> -- 
> Neil Cerutti
> If only faces could talk. --Pat Summerall




More information about the Python-list mailing list