intractable(?) Tkinter scrollbar problem

Greg McFarlane gregm at iname.com
Mon May 31 10:10:54 EDT 1999


I'm trying to perfect dynamic scrollbars (autoscrollbars) and have
come across a problem that I think is insoluble.  Under certain
circumstances, the two scrollbars are mapped and unmapped
continuously.

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.

Anyone seen this before? Or know of a workaround?

======================================================================
# Script which demonstrates continuous flashing (mapping/unmapping) of
# dynamic scrollbars (autoscrollbars).
#
# When this script is run, the two scrollbars will be continuously
# mapped and unmapped and the window will continuously change size.
#
# Script modified from Mark C Favas, using Fredrik Lundh's
# AutoScrollbar.

import Tkinter

class AutoScrollbar(Tkinter.Scrollbar): 
    def set(self, 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)

root = Tkinter.Tk()

frame = Tkinter.Frame(root)
frame.grid()
frame.columnconfigure(0, weight=1)
frame.rowconfigure(0, weight=1)

scrollFrame = Tkinter.Frame(frame)
scrollFrame.columnconfigure(1, weight=1)
scrollFrame.rowconfigure(1, weight=1)
scrollFrame.grid(sticky='news')

vscrollbar = AutoScrollbar(scrollFrame)
vscrollbar.grid(row=1, column=2, sticky='ns')
hscrollbar = AutoScrollbar(scrollFrame, orient='horizontal')
hscrollbar.grid(row=2, column=1, sticky='ew')

borderframe = Tkinter.Frame(scrollFrame)
borderframe.rowconfigure(0, weight=1)
borderframe.columnconfigure(0, weight=1)
borderframe.grid(row=1, column=1, sticky='news')

canvas = Tkinter.Canvas(borderframe,
        highlightthickness=0,
        borderwidth=0,
        background = 'red',
        width = 300,
        height = 200,
        scrollregion = (0, 0, 301, 200),
        yscrollcommand=vscrollbar.set,
        xscrollcommand=hscrollbar.set)
canvas.grid(sticky='news')
vscrollbar.config(command=canvas.yview)
hscrollbar.config(command=canvas.xview)

root.mainloop()
======================================================================

-- 
Greg McFarlane:    INMS Telstra Australia (gregm at iname.com)
Today's forecast:  Sunny, with occasional cloudy periods and a chance
		   of rain in some areas.




More information about the Python-list mailing list