#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2004
    Posts
    12
    Rep Power
    0

    Listbox and Scrollbar


    Hi,

    I have created a listbox with a corresponding scrollbar.

    When I add text to the listbox, under a conversation. The scrollbar doesnt go down automatically when the listbox is full of text. I have to manually move the scrollbar in order to view the latest received text. I havent found any options to let the scrollbar move automatically. Which would be the most logic and naturally way.

    Any idea to solve this?
    Code:
        def listbox_creator(self,string,frame):
            
            # create a simple label above the listbox
            h = Label(frame, text=string,fg=self.FG,font=('arial','12','bold'),justify=LEFT)
            h.grid(row=0,column=1,sticky=W)
    
            # insert a scrollbar to the listbox
            self.yScroll = Scrollbar(frame, orient=VERTICAL)
            self.yScroll.grid(row=1, column=0,sticky=N+S)
            lbox = Listbox(frame,fg=self.FG,bg=self.BG,\
                           selectbackground=self.FG,selectforeground=self.BG,\
                           selectmode=EXTENDED,\
                           width=self.width,height=self.height
                           )
    
            self.yScroll.config(command= lbox.yview)
            lbox.config(yscrollcommand=self.yScroll.set)
            
            lbox.grid(row=1,column=1, sticky=N+S+E+W)
            return lbox
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2004
    Location
    Regensburg, Germany
    Posts
    147
    Rep Power
    16
    Without knowing something about the GUI library you are using it's somewhat difficult to give an advice.
    Usually listbox classes have a method to make a specific listbox item visible (e.g. "see" for a TCL/TK listbox or "EnsureVisible" for a wxPyton wxListCtrl). Applying this method for the latest received text should scroll the list to make it visible and move the scrollbar automagically.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    394
    Rep Power
    51
    Hi!

    A Listbox has a function called see. I guess this is what you are looking for. Here is a little snippet to show it in action:
    Code:
    from Tkinter import *
    import time
    
    root = Tk()
    
    l = Listbox()
    l.pack(side=LEFT)
    scroll = Scrollbar(orient=VERTICAL)
    scroll.pack(side=RIGHT,fill=Y)
    scroll.config(command=l.yview)
    l.config(yscrollcommand=scroll.set)
    for i in range(20):
        l.insert(END,i)
        root.update()
        time.sleep(0.5)
        l.see(END)
    
    root.mainloop()
    Regards, mawe
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2004
    Posts
    12
    Rep Power
    0
    Thanks... see was the function I was looking for.

IMN logo majestic logo threadwatch logo seochat tools logo