Domanda

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!

È stato utile?

Soluzione

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")

Altri suggerimenti

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top