win32com how to catch events

igorjan2332 at igorjan2332 at
Wed Feb 27 11:49:10 CET 2013

I have a VBS sample code that I need to rewrite into python. It calls a com object which then generates events. My problem is that I don't know how to catch this events.
VBS sample looks like this:

Set oCOV = WScript.CreateObject( "RainbowObjectHandlerSrv.RainbowCOV", "oCOV_") ' like WithEvents in VB(A)

Sub oCOV_Update( ObjectId, ObjInstDataCOV)
       'some code
End Sub

I tried like this:

from win32com.client import DispatchWithEvents
class Events:
                def Update(self, ObjectID, Data):
                        print('update event')

oCOV = DispatchWithEvents("RainbowObjectHandlerSrv.RainbowCOV", Events)

my code can be found here:
but the event newer gets called. Any idea what I'm doing wrong?

More information about the Python-list mailing list