Select all in a tkinter Listbox
Question: I am creating a `Listbox` using Tkinter and Python. I want to make a Button
for `select all`, but I can't find any info regarding selecting elements using
code.

    
    
     self.l = Listbox(self, height=12, selectmode=MULTIPLE)
     self.selectAll=Button(self, text="select all",
                          command=self.selectAllCallback())
     def selectAllCallback(self)
     # What to do here
    


Answer: You can use
[`selection_set`](http://effbot.org/tkinterbook/listbox.htm#Tkinter.Listbox.selection_set-
method) (or `select_set`) method with `0` and `END` as arguments.

For example, try following code:

    
    
    from Tkinter import *
    
    def select_all():
        lb.select_set(0, END)
    
    root = Tk()
    lb = Listbox(root, selectmode=MULTIPLE)
    for i in range(10): lb.insert(END, i)
    lb.pack()
    Button(root, text='select all', command=select_all).pack()
    root.mainloop()
    

In the following statement, you are calling `self.selectAllCallback`, not bind
it with button click. It is called before the button is generated.

    
    
    self.selectAll=Button(self,text="select all", command=self.selectAllCallback())
                                                                                ^^
    

It should be:

    
    
    self.selectAll=Button(self, text="select all", command=self.selectAllCallback)
    

