Centered Scrolling Text

I’m creating a scrolling text game but im trying to figure out how to center the sys.stdout.write() to the screen. here’s some starter code i have:

from os import system
from time import sleep
import sys

black = "\033[0;30m"
purple = "\033[0;35m"
blue = "\033[0;34m"
green = "\033[0;32m"
red = "\033[0;31m"
yellow = "\033[0;33m"
white = "\033[0;37m"

def clear():
	system('clear')

def scrollTxt(text, color, speed):
	if color == "":
		for char in text:
			sys.stdout.write(char)
			sys.stdout.flush()
			sleep(speed)
		print()
	else:
		print(color, end="")
		for char in text:
			sys.stdout.write(char)
			sys.stdout.flush()
			sleep(speed)
		print()
		print(white, end="")


scrollTxt("Welcome...", blue, 0.1)

You need to know the width of the terminal. Use this:
https://docs.python.org/3/library/termios.html#termios.tcgetwinsize

Then pad on the left with enough spaces, computed from len(text).

BTW, not everybody’s terminal uses white text. Mine uses green. You want
to switch back to the 'default" colour, which has code 0.

Cheers,
Cameron Simpson cs@cskk.id.au