954,515 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Listbox Suggestions

How would I access the string that is in the [1] position of a tuple at a given index of a listbox. What I'm trying to do is something like this:

a=Lb1.curselection()[1]
    a=int(a)
    print(Lb1[a])

Lb1 is obviously the listbox. This particular attempt claims 1 is out of range "although I know it has a string in that position". With [0] in the position when it gets to Lb1[a] it claims, can't convert type int to str implicitly, however I wouldn't want to do that, because, futilely, I'm trying to index it.

pyguy62
Posting Whiz
353 posts since Aug 2011
Reputation Points: 34
Solved Threads: 19
 

or better yet how does this crazy ttk combobox thing work?

pyguy62
Posting Whiz
353 posts since Aug 2011
Reputation Points: 34
Solved Threads: 19
 
pyTony
pyMod
Moderator
5,359 posts since Apr 2010
Reputation Points: 782
Solved Threads: 852
 

That was extremely helpful. However I'm still having a hard time figuring out how to use the -autocomplete option and if I can make commands directly to the entry widget of the combobox separately.

pyguy62
Posting Whiz
353 posts since Aug 2011
Reputation Points: 34
Solved Threads: 19
 

Can you give reference, I do not find about that anything in documentation: http://www.tkdocs.com/tutorial/widgets.html

Only autocomplete I can find in widgets, is one entry widget stuff:
http://tkinter.unpythonic.net/wiki/AutocompleteEntry

Of course IDLE has autocomplete:
http://www.java2s.com/Open-Source/Python/3.1.2-Python/Lib/Lib/idlelib/AutoComplete.py.htm

pyTony
pyMod
Moderator
5,359 posts since Apr 2010
Reputation Points: 782
Solved Threads: 852
 

hmm, would I need to do multi-threading to have a loop continuously looking through what's in the entry field of the combobox? I really like the listbox that drops when you take a moment to think of what you're trying to type in tkinter, specifically I like how it goes directly to the closest match to what you've typed in. That's not the autocomplete is it?

pyguy62
Posting Whiz
353 posts since Aug 2011
Reputation Points: 34
Solved Threads: 19
 

No, event loop takes care of that, above code hooked to key release event.Then if you need repeated activity you can use after method of a widget. See the second link (maybe 2to3 script can prepare it for Python3, by the way you can install both Python2 and Python3 without too much confusion).

pyTony
pyMod
Moderator
5,359 posts since Apr 2010
Reputation Points: 782
Solved Threads: 852
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: