Change IDLE Shell window title

这一生的挚爱 提交于 2020-07-23 06:46:19

问题


I'm using multiple instances (idle/shell) of python and they both have the same title ('Python 3.8.1 Shell'). How I can change it directly from python shell? Os Windows.

I tried, but this is not helped me:

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

also tried:

>>> from os import system
>>> system("title " + 'abc')

Screenshot that demonstrates a same titles


回答1:


IDLE intentionally isolates its GUI, including Shell, from the running of your code. By default, they run in separate processes. If you start idle with 'python -m idlelib -n' so that GUI code and your code run in the same process, you might possibly break out of the within-process sandbox and change the window title. If you were to do so and said how, I might consider it a bug to be fixed.

What you can do from outside IDLE, is outside IDLE's control, and likely system dependent.

IDLE has a '-t title' startup option. python -m idlelib -t My-shell starts IDLE with a shell entitled "My-shell". To have a space in the title (and perhaps other chars, depending on the system), as with "My shell", quote it on the command line. On Windows, use double quotes, as I just did. I hope that this meets your need.

We could add 'Change title' to the Shell menu. But AFAIK you are the first to request this ability, and the IDLE charter is to keep it reasonably simple.




回答2:


for python 3

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

For python 2:

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

Edit

Try this code:

>>> import sys
>>> sys.stdout.write("\x1b]2;test\x07")

Where in place of test, put your name you want

Edit 2 Added screenshot for confirmation I am also using Windows See



来源:https://stackoverflow.com/questions/62709432/change-idle-shell-window-title

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!