【发布时间】:2020-09-06 09:23:00
【问题描述】:
我正在尝试构建一个程序,它可以让我获得我想要的文本的放大照片,为此我决定使用 tkinter、win32gui 和 pygetwindow 模块,在从已经提出的问题中获取一些提示后堆栈溢出存在以下问题:
(1)我不知道如何获取我创建的 tkinter 窗口的 hwnd 值。
(2)我无法获得 hwnd 值,即使我知道如何获取它,因为窗口是在完整代码运行后创建的。
所以请给我建议解决问题的方法
这是我的代码:
from tkinter import *
import win32gui
import pygetwindow as gw
#making the tkinter window
root = Tk()
root.title('DaysLeft')
#getting all the windows with their hwnd values
hwnd=gw.getAllWindows()
print(hwnd)
win32gui.SetForegroundWindow(hwnd)
bbox = win32gui.GetWindowRect(hwnd)
img = ImageGrab.grab(bbox)
img.show()
mainloop()
上面的代码在如预期的那样下面给出了错误:。
line 26, in <module>
win32gui.SetForegroundWindow(hwnd)
TypeError: The object is not a PyHANDLE object
【问题讨论】: