[Tkinter-discuss] How to handle any Windows message (eg. WM_GETOBJECT)?
Aivar Annamaa
aivar.annamaa at gmail.com
Tue Dec 10 16:36:07 EST 2019
Michael, thanks for the idea!
Unfortunately this does not work -- the callback is never called, even
if the app is sent WM_GETOBJECT messages.
But I found another promising approach -- swapping Tk's message handler
with my own handler:
import tkinter as tk
import win32gui
import win32con
root = tk.Tk()
button = tk.Button(root, text="close", command=root.destroy)
button.grid()
hwnd = root.winfo_id()
def new_wndproc(hWnd, msg, wParam, lParam):
if msg == win32con.WM_GETOBJECT:
print(hWnd, msg, wParam, lParam)
# forward message to original (Tk) handler
return win32gui.CallWindowProc(old_wndproc, hWnd, msg, wParam,
lParam)
# install new windows message handler
old_wndproc = win32gui.SetWindowLong(hwnd, win32con.GWL_WNDPROC,
new_wndproc)
root.mainloop()
I'll see where this road takes me.
Best regards,
Aivar
On 10.12.2019 13:11, Michael Lange wrote:
> Hi,
>
> On Tue, 10 Dec 2019 12:49:27 +0200
> Aivar Annamaa <aivar.annamaa at gmail.com> wrote:
>
>> Hi!
>>
>> It looks like accessibility support in Tk won't happen
>> (https://core.tcl-lang.org/tk/tktview/deb6cddecf55c6921281f8f855b6b366aed6467e).
>> I'm wondering is it somehow possible to bolt on some accessibility
>> support at least on Windows.
>>
>> It looks like the starting point is that the app should be able to
>> provide customized responses to WM_GETOBJECT messages. I didn't find
>> such name in Tk source code. Does it mean Tk event loop simply drops
>> these? Is it somehow possible to install an extra WM event handler to
>> catch these?
> have you tried to do something like
>
> def test():
> print('hello')
> root.wm_protocol('WM_GETOBJECT', test)
>
> I have no idea what WM_GETOBJECT does and if there is any chance that
> this will work, though :)
>
> Regards
>
> Michael
>
>
> .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-.
>
> I realize that command does have its fascination, even under
> circumstances such as these, but I neither enjoy the idea of command
> nor am I frightened of it. It simply exists, and I will do whatever
> logically needs to be done.
> -- Spock, "The Galileo Seven", stardate 2812.7
> _______________________________________________
> Tkinter-discuss mailing list
> Tkinter-discuss at python.org
> https://mail.python.org/mailman/listinfo/tkinter-discuss
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tkinter-discuss/attachments/20191210/0b69bd99/attachment.html>
More information about the Tkinter-discuss
mailing list