[Tutor] clickable listbox from sqlite database.

Alan Gauld alan.gauld at btinternet.com
Tue Jun 16 20:36:20 CEST 2015


On 16/06/15 13:47, Ali Moradi wrote:

> i want to fill the listbox from my database which contains of one table
> (Words) and two fields (English) and (Esperanto), how can i do that? i want
> the program to be the same just the words loaded from my sqlite database.

Do you know SQL?
And if so do you know how to call SQL from Python?

If the answer to either is no then can I suggest you read
my database topic in my tutorial, then come back here and ask again if 
it still doesn't make sense.

> and second thing: i want to search the word when user hits "Enter" on
> keyboard, so user doesn't have to click on search button all the time!

You need the Tkinter bind() function. It connects events to functions.
Using my code it will look something like:

eSearch = tk.Entry(top)
eSearch.pack()
eSearch.bind('<Return>', lambda e: search())

If you don't understand the lambda bit you could do it
this way instead...

modify search to be:

def search(event=None):
     target = eSearch.get()
     if target in words:
        tList.delete(0.0,tk.END)
        tList.insert(0.0,target)

And change the bind above to be:

eSearch.bind('<Return>', search)

Or just go and research lambda :-)

-- 
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