Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8144829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:29:09+00:00 2026-06-06T13:29:09+00:00

I am trying to format a string to display two columns for a high

  • 0

I am trying to format a string to display two columns for a high score table. Python is able to do this well when using print

print '{0:2d} {1:3d} {2:4d}'.format(x, x*x, x*x*x)

but when trying to use a formatted string, but becomes more challenging it seems. This is the result I am trying to get:

#for name, score in list: prints the following
1. FirstName LastName   45000
2. First LastName       78000
3. Fst Lst              11123
4. Name Name            40404
5. llll lll             12345

This is all one string that goes into a pygtk label. Currently I have this:

score_string += "%i. %-15.12s\t%15s\n" % (index, name, score)

which yields untrustworthy results. My current test data is displayed as the following:

1. Firstname Lastname          49900
2. First Last              93000
3. Name Name               6400

Because the first name in that list is longer than the rest (in width, not count of characters) the tab forces the score out of position. Is there a way to do this that not only takes the length of the string, but the width of the string into account as well?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T13:29:10+00:00Added an answer on June 6, 2026 at 1:29 pm

    You have two options:

    1. Change the font of the PyGTK label to a font that has equal width characters (not unreasonable in a game, it reminds us of the old arcade days). You can do this with set_markup of pango.Layout.

    2. Use two labels next to each other and use the method set_alignment of the class pango.Layout. The first label aligns the name to the left, the second label contains the score and it aligns to the right. As long as their is enough space the names and scores will align nicely to the left and right respectively.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to call Python's time.strftime() function using a Unicode format string: u'%d\u200f/%m\u200f/%Y
I was trying to align doubles using string.format and display them on a tooltip.
I am trying to extract datetime info from 2012/04/03 10:06:21:611747 using format String dateformat
I'm trying to output unicode string into RTF format. (using c# and winforms) From
I am currently trying to display the number and date(string format) of a json
I am trying to convert a string of this format: MM/dd/yyyy HH:mm The input
I'm trying to format a string to give me 2 characters for a number,
Trying to override a tostring in one of my classes. return string.Format(@ name =
I'm trying to figure out a way to format a date string that sits
I'm trying to parse a string in a specific format and I'm really surprised

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.