Set Windows command-line terminal title in Python

前端 未结 9 1954
攒了一身酷
攒了一身酷 2020-12-01 00:52

I\'m running several instances of a certain Python script on a Windows machine, each from a different directory and using a separate shell windows. Unfortunately Windows giv

9条回答
  •  [愿得一人]
    2020-12-01 01:24

    Due to not enough rep I cannot add a comment to the above post - so as a new post.

    In Python 3 you can use:

    import ctypes
    ctypes.windll.kernel32.SetConsoleTitleW("My New Title")
    

    I edited this answer: please remark, that it now uses SetConsoleTitleW, which is the Unicode version of the SetConsoleTitle function. This way you can use unicode and no longer have to encode the string/variable to a byte object. You can just replace the argument with the string variable.

提交回复
热议问题