Next / Previous / Contents / TCC Help System / NM Tech homepage

16.2. Connecting scrollbars to other widgets

Here is a code fragment showing the creation of a canvas with horizontal and vertical scrollbars. In this fragment, self is assumed to be a Frame widget.

    self.canv = Canvas ( self, width=600, height=400,
        scrollregion=(0, 0, 1200, 800) )
    self.canv.grid ( row=0, column=0 )

    self.scrollY = Scrollbar ( self, orient=VERTICAL,
        command=self.canv.yview )
    self.scrollY.grid ( row=0, column=1, sticky=N+S )

    self.scrollX = Scrollbar ( self, orient=HORIZONTAL,
        command=self.canv.xview )
    self.scrollX.grid ( row=1, column=0, sticky=E+W )

    self.canv["xscrollcommand"]  =  self.scrollX.set
    self.canv["yscrollcommand"]  =  self.scrollY.set

Notes: