Retrieve Tkinter listbox item by string, not by index
Godson
godson.g at gmail.com
Sat Dec 23 02:59:01 EST 2006
On 12/23/06, Kevin Walzer <kw at codebykevin.com> wrote:
>
> I'm trying to set the active item in a Tkinter listbox to my
> application's currently-defined default font.
>
> Here's how I get the fonts loaded into the listbox:
>
> self.fonts=list(tkFont.families())
> self.fonts.sort()
>
> for item in self.fonts:
> self.fontlist.insert(END, item) #self.fontlist is the
> ListBox instance
>
>
> So far, so good. But I don't know how to set the active selection in the
> listbox to the default font. All the methods for getting or setting a
> selection in the listbox are based on index, not a string. And using
> standard list search methods like this:
>
> if "Courier" in self.fontlist:
> print "list contains", value
> else:
> print value, "not found"
>
> returns an error:
>
> TypeError: cannot concatenate 'str' and 'int' objects
>
> So I'm stuck. Can someone point me in the right direction?
> --
> Kevin Walzer
> Code by Kevin
> http://www.codebykevin.com
> --
> http://mail.python.org/mailman/listinfo/python-list
>
to me self.fontlist to be a Listbox instance so you cant do a list search on
it, to get current selection from a list box use curselection method Listbox
self.fontlist.curselection()
returns a list of index numbers of currently selected items in a list box,
following link has more to say on this
http://effbot.org/tkinterbook/listbox.htm
--
Godson Gera,
http://godson.auroinfo.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20061223/4d35e021/attachment.html>
More information about the Python-list
mailing list