[英]How to get title name of console using python?
Is there any change of getting console title name instead of renaming it?获取控制台标题名称而不是重命名是否有任何变化? I know that I can use ie ctypes.windll.kernel32.SetConsoleTitleW to set new title of the console but I just want to get title name and do not set new title.
我知道我可以使用 ie ctypes.windll.kernel32.SetConsoleTitleW 来设置控制台的新标题,但我只想获取标题名称而不设置新标题。
不出所料,伴随函数是GetConsoleTitleW
。
Calling GetConsoleTitleW
is not enough to obtain the console title.调用
GetConsoleTitleW
不足以获取控制台标题。 Instead, you first need to create a buffer to hold that data and pass that.相反,您首先需要创建一个缓冲区来保存该数据并传递它。 Then, return the buffer's value.
然后,返回缓冲区的值。
The following function will return the console title:以下 function 将返回控制台标题:
import ctypes
def get_console_title():
BUF_SIZE = 256
buffer = ctypes.create_unicode_buffer(BUF_SIZE)
ctypes.windll.kernel32.GetConsoleTitleW(buffer, BUF_SIZE)
return buffer.value
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.