Next / Previous / Contents

14.1. Scrolling a Listbox widget

Here is a code fragment illustrating the creation and linking of a listbox to both a horizontal and a vertical scrollbar.

    self.yScroll = tk.Scrollbar(self, orient=tk.VERTICAL)
    self.yScroll.grid(row=0, column=1, sticky=tk.N+tk.S)

    self.xScroll = tk.Scrollbar(self, orient=tk.HORIZONTAL)
    self.xScroll.grid(row=1, column=0, sticky=tk.E+tk.W)

    self.listbox = tk.Listbox(self,
         xscrollcommand=self.xScroll.set,
         yscrollcommand=self.yScroll.set)
    self.listbox.grid(row=0, column=0, sticky=tk.N+tk.S+tk.E+tk.W)
    self.xScroll['command'] = self.listbox.xview
    self.yScroll['command'] = self.listbox.yview