update of elements in GUI

woooee woooee at gmail.com
Wed Aug 18 02:55:52 CEST 2010

On Aug 16, 9:07 pm, Jah_Alarm <jah.al... at gmail.com> 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 =" [i] 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
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.str_1 = Tkinter.StringVar()
        label_lit = Tkinter.StringVar()
        self.int_lit = Tkinter.IntVar()

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

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

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

        entry_1 = Tkinter.Entry(self.top, textvariable=self.str_1)
        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)


   def getit(self) :
       print "getit: variable passed =", self.str_1.get()
       x = self.int_lit.get()

if "__main__" == __name__  :
    print "under __main__ =", ET.str_1.get()

More information about the Python-list mailing list