intractable(?) Tkinter scrollbar problem

Mark C Favas mark at chem.uwa.edu.au
Sun Jun 6 21:44:28 EDT 1999


Dieter Maurer <dieter at handshake.de> writes:

>Greg McFarlane <gregm at iname.com> writes on Mon, 31 May 1999 14:10:54 GMT:
>> I include a Tkinter script below, modified from one by Mark C Favas,
>> using, I believe, Fredrik Lundh's AutoScrollbar class.  When this
>> script is run, the two scrollbars continuously get mapped and unmapped
>> and the window continuously changes size.

>I think, I now understand the instability and I should have
>a solution.

...<good explanation elided>...

>class AutoScrollbar(Tkinter.Scrollbar): 
>  _active= 0
>  def set(self, lo, hi):
>    self.lo= lo; self.hi= hi
>    #if self._active: print 'active'; return
>    self._active= 1; self.update_idletasks(); self._active= 0
>    self._set()
>  #
>  def _set(self):
>    lo= self.lo; hi= self.hi
>    #print self.id, lo, hi
>    if float(lo) <= 0.0 and float(hi) >= 1.0:
>      self.tk.call("grid", "remove", self)
>    else:
>      self.grid()
>    Tkinter.Scrollbar.set(self, lo, hi)

Thanks for your interesting explanation, Dieter. Interestingly, your fix as
posted, works, even though the test for self._active is commented out (it also
works if the test is uncommented). So, I tried the following, which also
works. The key is saving and restoring the values of lo and hi around the call
to self.update_idletasks()...

class AutoScrollbar(Tkinter.Scrollbar):
    def set(self, lo, hi):
        self.lo = lo
        self.hi = hi
        self.update_idletasks()
        lo = self.lo
        hi = self.hi
        if float(lo) <= 0.0 and float(hi) >= 1.0:
            self.tk.call("grid", "remove", self)
        else:
            self.grid()
        Tkinter.Scrollbar.set(self, lo, hi)

--
Email  - mark at chem.uwa.edu.au      ,-_|\                           Mark C Favas
Phone  - +61 9 380 3482           /     \               Department of Chemistry
Fax    - +61 9 380 1005      ---> *_,-._/   The University of Western Australia
                                       v                               Nedlands
Loc    - 31.97 S, 115.81 E                               Western Australia 6009




More information about the Python-list mailing list