PSXGamerPro1
PSXGamerPro1

Reputation: 182

Issue on resizing the Console Window in Python on Windows

I keep getting issues with this code.

def changeWindowSize():
   cmd = "mode con: cols=107 lines=50"
   resize = os.system(cmd)
   subprocess.Popen(resize)

It does work, but then also generates a Traceback.

Here is the Traceback: https://i.gyazo.com/e1fa638c083d2f05d391abf64a1e3778.png

Upvotes: 1

Views: 977

Answers (1)

falsetru
falsetru

Reputation: 368964

Call os.system is enough:

def changeWindowSize():
    cmd = "mode con: cols=107 lines=50"
    os.system(cmd)

If you want to use subprocess.Popen, call with shell=True:

def changeWindowSize():
    cmd = "mode con: cols=107 lines=50"
    subprocess.Popen(cmd, shell=True)
    #  OR  subprocess.call(cmd, shell=True)

The script failed because it passed an integer object (return value of os.system) to subprocess.Popen which accepts a list or a string as the first parameter.

Upvotes: 1

Related Questions