update of elements in GUI

Discussion in 'Python' started by Jah_Alarm, Aug 17, 2010.

  1. Jah_Alarm

    Jah_Alarm Guest

    hi, I've already asked this question but so far the progress has been
    small.

    I'm running Tkinter. I have some elements on the screen (Labels, most
    importantly) which content has to be updated every iteration of the
    algorithm run, e.g. "Iteration =" for i in range(n), n=100. I'm
    using the update_idletasks() command in the function itself after the
    variable.set(...) command. The variable type is IntVar(), and the
    mistake I'm getting is 'IntVar instance has no attribute
    'update_idletasks'. No updates are displayed, of course.

    Without the GUI the algorithm (it's a genetic algorithm) is working
    fine, but I need to make it available to other people via GUI

    cheers,

    Alex
     
    Jah_Alarm, Aug 17, 2010
    #1
    1. Advertising

  2. Jah_Alarm

    woooee Guest

    On Aug 16, 9:07 pm, Jah_Alarm <> wrote:
    I have some elements on the screen (Labels, most
    > importantly) which content has to be updated every iteration of the
    > algorithm

    The variable type is IntVar()

    You would use int_var_name.set(some_number)
     
    woooee, Aug 17, 2010
    #2
    1. Advertising

  3. Jah_Alarm

    Eric Brunel Guest

    In article
    <>,
    Jah_Alarm <> wrote:

    > hi, I've already asked this question but so far the progress has been
    > small.
    >
    > I'm running Tkinter. I have some elements on the screen (Labels, most
    > importantly) which content has to be updated every iteration of the
    > algorithm run, e.g. "Iteration =" for i in range(n), n=100. I'm
    > using the update_idletasks() command in the function itself after the
    > variable.set(...) command. The variable type is IntVar(), and the
    > mistake I'm getting is 'IntVar instance has no attribute
    > 'update_idletasks'. No updates are displayed, of course.


    You have to call update_idletasks on a Tkinter *widget*, not a variable.
    You can call it on your window (Tk or Toplevel instance) or on your
    label for example. This way, it should work.

    > Without the GUI the algorithm (it's a genetic algorithm) is working
    > fine, but I need to make it available to other people via GUI
    >
    > cheers,
    >
    > Alex
     
    Eric Brunel, Aug 17, 2010
    #3
  4. Jah_Alarm

    Jah_Alarm Guest

    thanks. The thing is, the objects actually get updated without this
    command, but when I run the GUI outside of python shell (i.e. in
    command prompt as python filename.py or compile it to .exe file) the
    objects do not get updated. I tried
    Label(mainframe,textvariable=var).grid(column=1,row=1).update_idletasks()
    and mainframe.update_idletasks() but it still doesn't work.


    On Aug 17, 7:19 pm, Eric Brunel <>
    wrote:
    > In article
    > <>,
    >
    >  Jah_Alarm <> wrote:
    > > hi, I've already asked this question but so far the progress has been
    > > small.

    >
    > > I'm running Tkinter. I have some elements on the screen (Labels, most
    > > importantly) which content has to be updated every iteration of the
    > > algorithm run, e.g. "Iteration =" for i in range(n), n=100. I'm
    > > using the update_idletasks() command in the function itself after the
    > > variable.set(...) command. The variable type is IntVar(), and the
    > > mistake I'm getting is 'IntVar instance has no attribute
    > > 'update_idletasks'. No updates are displayed, of course.

    >
    > You have to call update_idletasks on a Tkinter *widget*, not a variable.
    > You can call it on your window (Tk or Toplevel instance) or on your
    > label for example. This way, it should work.
    >
    >
    >
    > > Without the GUI the algorithm (it's a genetic algorithm) is working
    > > fine, but I need to make it available to other people via GUI

    >
    > > cheers,

    >
    > > Alex
     
    Jah_Alarm, Aug 17, 2010
    #4
  5. Jah_Alarm

    Jah_Alarm Guest

    In MATLAB this command is drawnow, just in case

    On Aug 17, 9:49 pm, Jah_Alarm <> wrote:
    > thanks. The thing is, the objects actually get updated without this
    > command, but when I run the GUI outside of python shell (i.e. in
    > command prompt as python filename.py or compile it to .exe file) the
    > objects do not get updated. I tried
    > Label(mainframe,textvariable=var).grid(column=1,row=1).update_idletasks()
    > and mainframe.update_idletasks() but it still doesn't work.
    >
    > On Aug 17, 7:19 pm, Eric Brunel <>
    > wrote:
    >
    >
    >
    > > In article
    > > <>,

    >
    > >  Jah_Alarm <> wrote:
    > > > hi, I've already asked this question but so far the progress has been
    > > > small.

    >
    > > > I'm running Tkinter. I have some elements on the screen (Labels, most
    > > > importantly) which content has to be updated every iteration of the
    > > > algorithm run, e.g. "Iteration =" for i in range(n), n=100. I'm
    > > > using the update_idletasks() command in the function itself after the
    > > > variable.set(...) command. The variable type is IntVar(), and the
    > > > mistake I'm getting is 'IntVar instance has no attribute
    > > > 'update_idletasks'. No updates are displayed, of course.

    >
    > > You have to call update_idletasks on a Tkinter *widget*, not a variable..
    > > You can call it on your window (Tk or Toplevel instance) or on your
    > > label for example. This way, it should work.

    >
    > > > Without the GUI the algorithm (it's a genetic algorithm) is working
    > > > fine, but I need to make it available to other people via GUI

    >
    > > > cheers,

    >
    > > > Alex
     
    Jah_Alarm, Aug 17, 2010
    #5
  6. Jah_Alarm

    Eric Brunel Guest

    (Top-post corrected; please don't do that, it makes messages very hard
    to read via usenetŠ)

    In article
    <>,
    Jah_Alarm <> wrote:
    > On Aug 17, 7:19 pm, Eric Brunel <>
    > wrote:
    > > You have to call update_idletasks on a Tkinter *widget*, not a variable.
    > > You can call it on your window (Tk or Toplevel instance) or on your
    > > label for example. This way, it should work.
    > >

    > thanks. The thing is, the objects actually get updated without this
    > command, but when I run the GUI outside of python shell (i.e. in
    > command prompt as python filename.py or compile it to .exe file) the
    > objects do not get updated. I tried
    > Label(mainframe,textvariable=var).grid(column=1,row=1).update_idletasks()
    > and mainframe.update_idletasks() but it still doesn't work.


    I think you're really misunderstanding something here: the call to
    update_idletasks is a one shot call to the GUI to basically tell it to
    refresh itself. So each time you change anything that should be
    displayed, you have to call that method again, or your changes will only
    be seen when the control returns to the GUI, which is basically at the
    end of your processing.

    The fact that it works when you're doing it interactively is normal. In
    this mode, you don't have a GUI event loop running, so the GUI updates
    itself all the time automatically. This is never true in programs you
    run the 'normal' way, i.e via: python filename.py

    And by the way, Label(Š).grid(Š).update_idletasks() had no chance to
    work anyway: the grid method doesn't return anything, so you're trying
    to call the update_idletasks method on None hereŠ

    HTH
    - Eric -
     
    Eric Brunel, Aug 17, 2010
    #6
  7. Jah_Alarm

    woooee Guest

    On Aug 16, 9:07 pm, Jah_Alarm <> wrote:
    > hi, I've already asked this question but so far the progress has been
    > small.
    >
    > I'm running Tkinter. I have some elements on the screen (Labels, most
    > importantly) which content has to be updated every iteration of the
    > algorithm run, e.g. "Iteration =" for i in range(n), n=100. I'm
    > using the update_idletasks() command in the function itself after the
    > variable.set(...) command. The variable type is IntVar(), and the
    > mistake I'm getting is 'IntVar instance has no attribute
    > 'update_idletasks'. No updates are displayed, of course.
    >
    > Without the GUI the algorithm (it's a genetic algorithm) is working
    > fine, but I need to make it available to other people via GUI
    >
    > cheers,
    >
    > Alex


    This program I had lying around and it will hopefully make things
    clearer. The integer under the second label (i.e. the 3rd label)
    increases by on every time you click the "Print Contents" button. The
    variable associated with the second label and the entry box update as
    you change the entry box's contents, all with no calls to
    update_idletasks().
    class EntryTest:
    """ shows using the same StringVar in the second list box
    and in the entry box
    """
    def __init__(self):
    self.top = Tkinter.Tk()
    self.top.title("Test of Entry")
    self.top.geometry("200x150+10+10")

    self.str_1 = Tkinter.StringVar()
    label_lit = Tkinter.StringVar()
    self.int_lit = Tkinter.IntVar()

    label_1 = Tkinter.Label(self.top, textvariable = label_lit )
    label_1.pack()
    label_lit.set( "Test of Label")

    label_2 = Tkinter.Label(self.top, textvariable = self.str_1 )
    label_2.pack()

    label_3 = Tkinter.Label(self.top, textvariable =
    self.int_lit )
    label_3.pack()
    self.int_lit.set(0)

    entry_1 = Tkinter.Entry(self.top, textvariable=self.str_1)
    entry_1.pack()
    self.str_1.set( "Entry Initial Value" )

    print_button = Tkinter.Button(self.top, text='PRINT CONTENTS',
    command=self.getit, bg='blue', fg='white' )
    print_button.pack(fill=Tkinter.X, expand=1)

    exit_button= Tkinter.Button(self.top, text='EXIT',
    command=self.top.quit, bg='red', fg='white' )
    exit_button.pack(fill=Tkinter.X, expand=1)

    entry_1.focus_set()
    self.top.mainloop()

    ##-----------------------------------------------------------------
    def getit(self) :
    print "getit: variable passed =", self.str_1.get()
    x = self.int_lit.get()
    self.int_lit.set(x+1)


    ##===============================================================
    if "__main__" == __name__ :
    ET=EntryTest()
    print "under __main__ =", ET.str_1.get()
     
    woooee, Aug 18, 2010
    #7
    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. paul.foreman

    GUI - GUI value passing

    paul.foreman, Oct 22, 2004, in forum: Java
    Replies:
    5
    Views:
    762
    Michael Rauscher
    Oct 25, 2004
  2. ulysses
    Replies:
    4
    Views:
    777
    Werner Schiendl
    Oct 22, 2003
  3. Andrew Lapidas

    PyGTK GUI update without signals from GUI

    Andrew Lapidas, Apr 13, 2008, in forum: Python
    Replies:
    0
    Views:
    419
    Andrew Lapidas
    Apr 13, 2008
  4. Stefan Ram
    Replies:
    3
    Views:
    498
    Arne Vajhøj
    Nov 20, 2011
  5. Hal Fulton

    GUI and non-GUI data

    Hal Fulton, Aug 5, 2004, in forum: Ruby
    Replies:
    1
    Views:
    146
    Austin Ziegler
    Aug 5, 2004
Loading...

Share This Page