pygtk get window hwnd

Searching "pygtk get window hwnd" on Google for a while, I found there is not much help in top results. So I decide to write this short article.

gtk.Window has a property called "window", it's almost same level as Window in winapi.

Running above code will get following output:

<gtk.gdk.Window object at 0x2713be8 (GdkWindow at 0x1d9e160)>

Then we can get the hwnd by retrieving "handle" property of this gtk.gdk.Window object


pygtk gobject.timeout_add() won’t work after calling gtk.threads_init() on windows xp

I have a pygtk program which starts a separate thread to receive HTTP request from user and display message dialogs by checking a string variable every 500 ms. It works well on Windows 7, but testing on Windows XP failed: the GUI blocked and no window is showed.

Gradually I found gobject.timeout_add() function is not working, in fact, it didn't work after calling gtk.threads_init().I reduced unrelated code and got following simplest situation to reproduce the issue.

Following simple code will hang forever on windows XP, and the "check dialog" text is never outputted to console. The window created in the code showed but is blocked (when I move mouse into the window area, the mouse pointer is always a "loading" icon)

If we remove gtk.threads_init(), code will work.

To solve this issue, just replace gtk.threads_init() with gobject.threads_init()