Simple Tkinter problem

Discussion in 'Python' started by gmarkowsky@gmail.com, Nov 7, 2006.

  1. Guest

    Hi all,

    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? 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.

    Greg
    , Nov 7, 2006
    #1
    1. Advertising

  2. Neil Cerutti Guest

    On 2006-11-07, <> 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
    Neil Cerutti, Nov 7, 2006
    #2
    1. Advertising

  3. Guest

    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, <> 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
    , Nov 7, 2006
    #3
  4. jim-on-linux Guest

    Greg,

    Run the following code to see how pack_forget() or
    grid_forget() works, it makes previous widgets
    disappear but not go away. If you call grid() or
    pack() again after using grid_forget() the widget
    returns.


    root = Tk()
    class Ktest:
    def __init__(self):
    self.Ftest1()

    def Ftest1(self):

    try:
    self.test2.grid_forget()
    except AttributeError :
    pass
    self.test1 = Button(root, text='Push #1
    button', bg = 'yellow', width = 25,
    command = self.Ftest2,
    height = 25)
    self.test1.grid(row=0, column=0)


    def Ftest2(self):
    self.test1.grid_forget()
    self.test2 = Button(root, text='Push #2
    button', bg = 'green',
    width = 15,
    command = self.Ftest1,
    height = 10)
    self.test2.grid(row=0, column=0)

    if __name__== '__main__' :
    Ktest()
    mainloop()



    Maybe someone else has an idea about not defining
    a variable.

    My question is how does a budket of wires and
    screws know its a bucket of wires and screws
    unless someone tells it that it's a bucket of
    wires and screws?








    On Tuesday 07 November 2006 09:35,
    wrote:
    > Hi all,
    >
    > 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? 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.
    >
    > Greg
    jim-on-linux, Nov 7, 2006
    #4
  5. jim-on-linux Guest

    On Tuesday 07 November 2006 10:38, jim-on-linux
    wrote:
    Greg,

    Run the following code to see how pack_forget()
    or grid_forget() works, it makes previous
    widgets disappear but not go away. If you call
    grid() or pack() again after using
    grid_forget() the widget returns.


    root = Tk()
    class Ktest:
    def __init__(self):
    self.Ftest1()

    def Ftest1(self):

    try:
    self.test2.grid_forget()
    except AttributeError :
    pass
    self.test1 = Button(root, text='Push #1
    button', bg = 'yellow',
    width = 25,
    command = self.Ftest2, height = 25)
    self.test1.grid(row=0, column=0)


    def Ftest2(self):
    self.test1.grid_forget()
    self.test2 = Button(root, text='Push #2
    button', bg = 'green',
    width = 15,
    command = self.Ftest1,
    height = 10)
    self.test2.grid(row=0, column=0)

    if __name__== '__main__' :
    Ktest()
    mainloop()



    Maybe someone else has an idea about not
    defining a variable.

    My question is how does a budket of wires and
    screws know its a bucket of wires and screws
    unless someone tells it that it's a bucket of
    wires and screws?

    jim-on-linux

    http://.www.inqvista.com

    >
    >
    >
    >
    >
    > On Tuesday 07 November 2006 09:35,
    >
    > wrote:
    > > Hi all,
    > >
    > > 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? 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.
    > >
    > > Greg
    jim-on-linux, Nov 8, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jeff Epler
    Replies:
    0
    Views:
    504
    Jeff Epler
    Aug 20, 2004
  2. Jeff Epler
    Replies:
    0
    Views:
    450
    Jeff Epler
    Aug 23, 2004
  3. Pierre Dagenais
    Replies:
    0
    Views:
    308
    Pierre Dagenais
    Aug 3, 2008
  4. Hidekazu IWAKI
    Replies:
    1
    Views:
    376
    Peter Otten
    Dec 14, 2009
  5. Hidekazu IWAKI
    Replies:
    0
    Views:
    521
    Hidekazu IWAKI
    Dec 15, 2009
Loading...

Share This Page