[Tutor] Getting current listbox item index and bind it to button (Tkinter)

Alan Gauld alan.gauld at yahoo.co.uk
Thu Aug 2 18:40:48 EDT 2018


On 02/08/18 21:12, Ali M wrote:

> I tried writing the search_word function and binded it to the button, but
> it doesn't work, please help i'm still a beginner.
> 
>     def search_word(self, tag):
>         esperanto = self.listbox.selection_set(0)
>         results = self.cur.execute("SELECT English FROM Words WHERE
> Esperanto = ?", (esperanto,))
>         for row in results:
>             self.textbox.delete(1.0, tk.END)
>             self.textbox.insert(tk.END, row[0])


The last bit looks suspicious.
You delete the contents of textbox each time round the loop.
Surely you only want to delete it once before the loop?


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list