How to align a text of a Listbox to the right

Sori Schwimmer sxn02 at yahoo.com
Fri Apr 28 15:30:32 EDT 2006


Eric Brunel is right in that a Listbox won't provide
any builtin help for this kind of things.

Suppose you can afford a width of 10 chars. Suppose
your lines are stored in the variable Lines - a
sequence. Suppose you use a font with fixed width (the
width occupied by "i" is the same like for "m").

lBox = Listbox(parent, width=10)
for i in Lines:
  if len(i) > 10:
    lBox.insert(END, i[-10:])
  else:
    lBox.insert(END, ('%10s' % i))

For more on string formatting, check chapter 2.3.6.2
in Python's documentation.

Good luck!
Sorin Schwimmer

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 



More information about the Python-list mailing list