Listbox with scrollbar

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Appu2008
    New Member
    • Dec 2007
    • 18

    Listbox with scrollbar

    Hi,
    Iam using Python 2.5 and developing an application using Tkinter.
    I want a listbox with scrollbar. I tried to combine both
    but it gets filled in the entire screen.

    Here is the code..

    frm=Frame(root, height=400,widt h=400)
    frm.pack()
    scrollbar1=Scro llbar(frm)
    scrollbar2=Scro llbar(frm)
    scrollbar1.pack (side=RIGHT,fil l=Y)
    scrollbar2.pack (side=BOTTOM,fi ll=X)
    listbox=Listbox (frm,width=400, height=400)
    listbox.pack()
    listbox.config( yscrollcommand= scrollbar1.set)
    scrollbar1.conf ig(command=list box.yview)
    listbox.config( xscrollcommand= scrollbar2.set)
    scrollbar2.conf ig(command=list box.xview)

    How to position this scrollbar in a particular
    position??Also is there any table widget
    in Tkinter that i can use in windows. I think tktable widget
    works only for linux..
    Pls help
  • jlm699
    Contributor
    • Jul 2007
    • 314

    #2
    It would help us all a great deal if you could use CODE tags around your code to make it easier to read.
    Please read the posting guidelines before posting, particularly the "How the ask a question" section.

    Comment

    • woooee
      New Member
      • Mar 2008
      • 43

      #3
      I prefer to use the PMW extension to Tkinter. PMW has a scrolled listbox widget. This is something I had lying around.

      In answer to your question, TableList will run on any OS that has TCL/Tk installed http://www.nemethi.de/
      Code:
      import Tkinter 
      import Pmw  
      class PMWListBox :
         def __init__( self, list_in, min_width=300, min_height=350 ) :
            self.top = Tkinter.Tk()       
            self.top.geometry( "300x300+10+10" )   
            self.top.minsize( min_width, min_height )
            self.top.option_add('*Font', 'Fixed 14')
            Pmw.initialise( fontScheme='default')
            #---  exit button must be first----------------------
            exit = Tkinter.Button(self.top, text='EXIT',
                       command=self.top.quit, bg='lightblue', fg='yellow' )
            exit.pack(fill="x", expand=1, side="bottom")
            #----------------------------------------------------------------
            scroll_box = Pmw.ScrolledListBox( self.top, \
                                listbox_selectmode="SINGLE", \
                                items=(list_in) )
            scroll_box.pack(fill="both", expand=1, padx=5, pady=5, side="top" )
            self.top.mainloop()
      ##=======================================
      if __name__ == "__main__" :
          list_items=["First List Entry", "Second List Entry", \
                     "Third List Entry", \ 
                     "Fourth List Entry -- W I D E -- W  I  D  E", \
                     "Fifth List Entry", "Sixth Entry", "Seventh Entry" \
                     "Eighth Entry", "Ninth Entry", "Tenth Entry", \
                     "Entry # 11 Test", "Test for 12th Lit", \
                     "Thirteen", "Fourteen", "Fifteen"]
          PM = PMWListBox( list_items )

      Comment

      Working...