0

Alright, I asked my question last time in a untimely manner, what I should have asked is how do I CENTER the question asked in the middle of the screen? I included this screenshot last time, I want the question in the MIDDLE of the screen :D. Sorry. Techhelp.img

Thanks! Any help is much appreciated!

braX
  • 11,506
  • 5
  • 20
  • 33
boatofturtles
  • 115
  • 1
  • 2
  • 10
  • See [this](http://stackoverflow.com/questions/13383244/python-centre-string-using-format-specifier) question, and maybe this snippet works for you?: http://www.aliendev.com/programming/snippet-friday-programming/quick-snippet-friday-center-text-in-a-console-python-program – Linuxios Apr 05 '14 at 20:01

2 Answers2

1

You can define a special printing function like this:

terminal_width = 80  # Change this if necessary.

def center_print(s):
    print '{:^terminal_width}'.format(s)

And call it when you need output in the center. So call that function instead of print for your questions.

anon582847382
  • 19,907
  • 5
  • 54
  • 57
1

Using screen width detection from here

def center_print(s):
    import os,sys
    command = "mode con ^ | findstr Columns" if sys.platform == 'win32' else "stty size"
    ignore, columns = os.popen(command).read().split()
    print " "*((int(columns)-len(s))/2)+s

center_print("aaaaaaaaaaaaaaaa")
Community
  • 1
  • 1
Ilya Kharlamov
  • 3,698
  • 1
  • 31
  • 33