I'm trying to make a simple search listbox which will have quite a few variables in it therefore making it necessary to have a 'clear selected' function. For this I've created a 'Clear' button and tried to link it using tk's selection_clear function. Unfortunately I cannot get it to work. Could you please point me in the right direction?
Code extract:
class Application(tk.Frame):
def __init__(self, master=None):
tk.Frame.__init__(self, master)
self.grid(sticky=tk.N+tk.S+tk.E+tk.W)
self.create_widgets()
def create_widgets(self):
top = self.winfo_toplevel()
top.rowconfigure(0, weight=1)
top.columnconfigure(0, weight=1)
self.rowconfigure(0, weight=1)
self.columnconfigure(0, weight=0)
parameters_list_1 = 'foo', 'bar', 'foofoo', 'barbar', 'foobar'
self.sb1_values = tk.Variable(value=parameters_list_1)
self.search_listbox = tk.Listbox(self, activestyle='dotbox', listvariable=self.sb1_values, selectmode=tk.MULTIPLE)
self.search_listbox.grid(row=3, column=1, sticky=tk.N+tk.S+tk.E+tk.W)
self.clear_button = tk.Button(self, text='Clear', command=self.search_listbox.selection_clear(0, tk.END))
self.clear_button.grid(row=4, column=2, sticky=tk.N+tk.S+tk.E+tk.W)
app = Application()
app.master.title('GUI')
app.mainloop()
Thank you in advance
Replace command=self.search_listbox.selection_clear(0, tk.END)
by command=lambda : self.search_listbox.selection_clear(0, tk.END)