Python: How to get the text label from another program window?

℡╲_俬逩灬. 提交于 2019-12-03 03:52:52

If the text of your window has more than 20 characters, then the buffer you have created is too small. Try expanding it to more than you're likely to need:

buffer = win32gui.PyMakeBuffer(255)
length = win32gui.SendMessage(control, win32con.WM_GETTEXT, 255, buffer)

If you want to get to the controls within the main window, then use EnumChildWindows, passing the handle of the parent window. You may need to do this recursively.

win32gui.PyMakeBuffer has been deprecated. Also, buffer is a builtin function, so don't use it as a variable name.

Instead, just do this:

buf = " " * 255
length = win32gui.SendMessage(control, win32con.WM_GETTEXT, 255, buf)
result = buf[:length]
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!