Tkinter Listbox string formatting question - how to kill a dancing snake ?

Hendrik van Rooyen mail at microcorp.co.za
Tue Oct 31 02:33:55 EST 2006


I am populating a listbox from a directory that looks like this:

variable_dict = {"funny_long_or_short_variable_name_as_key": (2,45),......

the tuple represents a "card, line" pair.
medf is a font object and a forward reference here.

I write:

for x in variable_dict:
    txt = x
    while medf.measure(txt) < 350:
        txt = txt + ' '
    txt = txt + str(variable_dict[x])

and I use the txt string to populate the list box.

At first glance, it seems to work, as the names are on the left, and the tuples
are in a column...

But if you scroll the listbox, the inherent error makes it appear as if the
tuple column is a snake doing the twist.

I tried using a tab but got a backslash - t in the text, and simply counting
spaces is worse than useless.

Is there a way to format this so it will line up with  *any*  font ?

I would prefer not to give up and use a fixed width font - it looks so
teletypish...

A blank char of one pixel width would sort this nicely - but as the hilbilly
said when he first saw a rhinoceros: " There aint no such animal! "  -  or is
there?

- Hendrik




More information about the Python-list mailing list