如何在 Windows 上获取 Tkinter 窗口的 HWND? [英] How to get the HWND of a Tkinter window on Windows?

查看:48
本文介绍了如何在 Windows 上获取 Tkinter 窗口的 HWND?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在windows上的python3中获取Tkinter窗口的HWND?

How to get the HWND of a Tkinter window in python3 on windows?

  • 如果可能,我想获取 Tkinter 窗口的本机窗口句柄.
  • 我需要窗口的 HWNDHDC 来执行自定义绘图操作.
  • I would like to get the native window handle of the Tkinter window if possible.
  • I would need either the HWND or HDC of the window to perform custom drawing operations.

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

Is there a way to get the HWND of the Canvas or any other child components?

有一种方法可以列出当前进程创建的所有窗口.我还可以遍历前面列出的任何窗口的子窗口.这将是该问题的丑陋的解决方案.

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 不直接暴露句柄,请发布任何替代解决方案.

Please post any alternative solutions if Tkinter does not expose the handle directly.

推荐答案

我相信你需要的是 TopLevel 窗口方法.

I believe what you need is the TopLevel window method.

看看这个link

frame() [#]
返回一个字符串,其中包含与窗口最外层父级对应的系统特定窗口标识符.对于 Unix,这是 X 窗口标识符.对于 Windows,这是转换为长整数的 HWND.

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 的其他信息 此处.

There is also additional information about getting the HWND here.

winfo_id() [#]
获取此小部件的系统特定窗口标识符.对于 Unix,这是 X 窗口标识符.对于 Windows,这是转换为长整数的 HWND.

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(),你应该能够得到窗口的 HWND.

I believe using winfo_id() above, you should be able to get the HWND of the window.

这篇关于如何在 Windows 上获取 Tkinter 窗口的 HWND?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆