470,835 Members | 1,902 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,835 developers. It's quick & easy.

How to align a text of a Listbox to the right

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
Apr 28 '06 #1
0 1231

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Stan Brown | last post: by
10 posts views Thread by Markus Ernst | last post: by
8 posts views Thread by André Hänsel | last post: by
2 posts views Thread by Tom McL. | last post: by
3 posts views Thread by Leonardo da Vinci | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.