Tkinter: activate method on listbox question

Tim Daneliuk tundra at tundraware.com
Mon Nov 25 21:00:07 EST 2002


I have a listbox defined which displays a directory listing.  The listbox is
initialized in EXTENDED mode.  I have '<Double-ButtonRelease-1>' bound to
a routine which figures out which file names the user has selected and
proceeds to do something about it.

So far, so good - it works.  However, say the user double-clicks on another
directory somewhere down the listbox.  The routine which moves to the new
directory does its thing (erases the listbox and loads it with that new
directory's content) and (here's the key part) does this:

             UI.DirList.select_set(('0',))
             UI.DirList.activate(0)

That is, I want both the selection and the activation to be initialized
to the first item in the new directory listing.

Here's the problem.  The selection is indeed set to the first item, BUT,
somehow, the activation is getting reset to the previous value (i.e. - the
value it had when the new directory was selected.)  For example, suppose
we have this directory layout:

                     /
                       foo/
                       bar/
                            bar1
                            bar2
                       baz/

If I double-click on bar/, the listbox is properly reloaded with this:

                      ../
                      bar1
                      bar2

And ../ is selected as I would expect.  However, *bar2* has the activation
which is the same index in this directory, as bar had in the previous directory.

As near as I can tell, this is some sort of Tk madness that is setting the activation
to its last value *after* I have set it to 0.

Ideas?
-- 
------------------------------------------------------------------------------
Tim Daneliuk
tundra at tundraware.com




More information about the Python-list mailing list