Change IDLE Shell window title
Asked Answered
A

2

1

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 Screenshot with same titles

Adalai answered 3/7, 2020 at 6:8 Comment(1)
python's IDLE is not a terminal window....Myxoma
R
0

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.

Reopen answered 4/7, 2020 at 0:36 Comment(0)
C
3

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 Screenshot

Capitalization answered 3/7, 2020 at 6:21 Comment(14)
unfortunately, this is also not helped meAdalai
What output you are getting? Where have you tried it?Capitalization
output: >>> ctypes.windll.kernel32.SetConsoleTitleW("My New Title") 0 >>> I was tried it directly in the shell. Task manager also don't showing any changesAdalai
no :( >>> import sys >>> sys.stdout.write("\x1b]2;test\x07") ]2;test9 img linkAdalai
Why you wriiten 2;test9 ? I guess you have written this code wrong . It works fine for meCapitalization
This is exactly what are you typed. I just copied it without any changes.Adalai
Bro, I can't see 9 anywhere in my code. Just paste sys.stdout.write("\x1b]2;test\x07") in the shell and see for yourselfCapitalization
you missed r before a string in your code, but even with it nothing changes. I'm using windows. >>> sys.stdout.write(r"\x1b]2;qwerty\x07") \x1b]2;qwerty\x0717 >>> Adalai
For you @AdalaiCapitalization
For you @salius, I've added a scrrenshot. See for yourself in the editsCapitalization
I get you! You run it from the powershell, and I'm running python directly link P.S. In this sample I changed a title BEFORE running the pythonAdalai
Did you get what you were looking for?Capitalization
Mainly no, because I asked to change the title during the session itself, not before or outside (Powershell)Adalai
In your screenshot, you appear to run python REPL directly, in a PowerShell window. OP appears to be asking about changing the window title for IDLE's Shell simulation of the REPL, whose title is set by IDLE with a tkinter (tk) call.Reopen
R
0

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.

Reopen answered 4/7, 2020 at 0:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.