如何在 Windows 上获取 Tkinter window 的 HWND?

How to get the HWND of a Tkinter window on Windows?

如何在 windows python3 中获取 Tkinter window 的 HWND

有没有办法获取 Canvas 或任何其他子组件的 HWND

There is a way to list all the windows created by the current process. I am also able to iterate through the child windows of any window listed previously. This would be the ugly solution for the problem.

如果 Tkinter 不直接公开句柄,请post任何替代解决方案。

我相信您需要的是 TopLevel window 方法。

看看这个link

frame() [#]
Returns a string containing a system-specific window identifier corresponding to the window’s outermost parent. For Unix, this is the X window identifier. For Windows, this is the HWND cast to a long integer.

还有关于获取 HWND 的附加信息here.

winfo_id() [#]
Get a system-specific window identifier for this widget. For Unix, this is the X window identifier. For Windows, this is the HWND cast to a long integer.

    Returns:
      The window identifier.

我相信使用上面的winfo_id(),你应该能够得到window的HWND。