[Tutor] Clickable listbox in Tkinter python 2

Alan Gauld alan.gauld at btinternet.com
Mon Jun 15 17:57:05 CEST 2015


On 15/06/15 14:41, Ali Moradi wrote:

> the listbox should be on the same frame under the entry widget and the
> whole list should be visible, when the user types the word in Entry widger
> and clicks on search button, the listbox narrows down to that word only and
> now just (for example: water    akvo) are visible. do you know what i mean?
> i'm not native english speaker so maybe i can't explain it :(

OK I think I've got it. You might want to make the list scrollable since 
there will probably be more entries than can fit in a single widget at 
one time.

As to making the list shrink down to a single entry, that will be
your job, it is not a standard feature. Essentially you will need to 
select all the pairs initially from SQLite and then select only the 
matching pair after a search. If you don't know how to do database 
searches from Python ask about that in a separate thread.

As to the layout something like(for Python 3):

import tkinter as tk

words = ['a','list','of','strings']

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

top = tk.Tk()

eSearch = tk.Entry(top)
eSearch.pack()
tList = tk.Text()
tList.insert(0.0, '\n'.join(words))
tList.pack()
bSearch = tk.Button(top, text='Search', command=search)
bSearch.pack()

top.mainloop()


is as simple as it gets. You can modify the sizes by using the 
width/height widget options of course. You can be much more 
sophisticated but that should get you started.


> http://qfs.mobi/f2361208
>
> https://drive.google.com/file/d/0Bwe9iYyAhRzgT3hudnAxUkVzTTA/view?usp=sharing

Neither of those show me code, they seem to want me to download 
something. Since I never download from untrusted sources I can't
see the code. Try pasting it somewhere like

http://www.pastebin.com


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