John Smith John Smith - 2 years ago 84
Python Question

Formatting string not working

I have done some research on formatting string but it does not want to work for me. I have this

for i in range(0,10):
stat = arr[i]
highscoreText = GameFont.render('{0:12}{1:>0}'.format(stat["Name"],stat["Score"]),2,(255,255,255))
Screen.blit(highscoreText,[50,50 + (i*30)])

The name works but I can't seem to make the Score align to the right.

Answer Source

The string formatting works as expected. Try to print formatted sting in console. The problem with the font you use. See, ll in hello take the same span as k below.
To solve this you have to render names and scores separately and then blit them at appropriate positions.
Or you can change the font you use to a monospace, like Courier or Dejavu mono

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download