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



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

.



Relevant Pages

  • Re: Owner drawn listbox
    ... Pass a reference of the listbox to the ... OwnerDrawListBox object, and use the objects Add method for adding items to ... ' Currently if a row is 'special', then the current font is ... Public Sub Add ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Lebans Tooltip Control : Listbox font size
    ... time when calculating the font height for a row in the ListBox. ... you can turn off the column header Tooltip by NOT enabling Column ...
    (microsoft.public.access.forms)
  • Re: Listboxes results based on table joins
    ... Dim strSQL as String ... List3 for some reason is not populating when I select updated values ... Here is my sql in the Row Source (for the second listbox that connects ... incorporating its name into the SQL string. ...
    (microsoft.public.access.formscoding)
  • Re: Center align text in list box
    ... As Jeff and Jan have already said, you could use a fixed width font and pad with spaces or you could use a different control or you could subclass a standard ListBox to achieve the effect you desire. ... You can easily add code to calculate the pixel width of the string, either using the appropriate API functions or by simply assigning the listBox Font to a spare Picture Box font and using the PictureBox TextWidth function. ...
    (microsoft.public.vb.general.discussion)
  • Re: Lebans Tooltip Control : Listbox font size
    ... Are you suggesting that the listbox has to be 'dynamically sized' at runtime ... save time when calculating the font height for a row in the ListBox. ... you can turn off the column header Tooltip by NOT enabling Column ...
    (microsoft.public.access.forms)