[Tutor] Tk Listbox scrollbars
Isaac Hall
hall@ouhep1.nhn.ou.edu
Tue Jan 7 18:46:25 2003
Hi Andy,
You are in luck. I had to write this exact thing not long ago, so I will
just copy for you the code that I have written to do this. It is in the
form of a class, but I you can take the important things out of it.
I use grid here, but pack can be used in the same way.
I should note that when I used pack, the thing looked a little different,
but not by much. The only difference here in calling this instead of a
listbox is that the box is class.box
from Tkinter import *
class ScrolledListbox(Frame):
def __init__(self,parent):
Frame.__init__(self,parent)
self.yScroll=Scrollbar(self,orient=VERTICAL)
self.xScroll=Scrollbar(self, orient=HORIZONTAL)
self.box=Listbox(self,xscrollcommand=self.xScroll.set,
yscrollcommand=self.yScroll.set,bg='white')
self.box.grid(row=0,column=0,sticky=N+S+E+W)
self.xScroll.grid(row=1,column=0,sticky=E+W)
self.yScroll.grid(row=0,column=1,sticky=N+S)
self.xScroll["command"]=self.box.xview
self.yScroll["command"]=self.box.yview
Ike
On Tue, 7 Jan 2003, andy surany wrote:
> Hello all,
>
> I wrote a program for a scrolled list containing a Y-axis scrollbar
> which has been working fine. At this point, my data is also overflowing
> the width of the box, so I have added an X-axis scrollbar.
>
> Both scrollbars appear, but the x-axis scrollbar is "vertical" (and
> tiny...and I press the up or down arrow to move left or right). What I
> want is a "slider" similar to the y scroll bar. I'm pretty sure that the
> error is in the way that I am packing the widget, as follows:
>
> sbar.pack(side=RIGHT, fill=Y) # This is for the Y-axis bar and it works
> correctly
> tbar.pack(side=BOTTOM) # This places the X-axis bar as described above
>
> TIA
>
> -Andy
>
>
>
> _______________________________________________
> Tutor maillist - Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
--