Trackpad Interactions

I am trying to understand which Events correspond to trackpad events.
When I create a vtkSphereWidget and click on it using my Mac trackpad, it lights up - so I know vtk can accept trackpad events.

However, when I took that same tutorial and tried to create my own Callback that gets run when a trackpad click is applied to the sphere, none of the events I tried worked:

import vtk

# Call back function

def sphereCallback(obj, event):
    print(f'obj is \n{obj}\n event is {event}')

def main():
    colors = vtk.vtkNamedColors()

    # colors.SetColor('bkg', [0.1, 0.2, 0.4, 1.0])

    # A renderer and render window
    renderer = vtk.vtkRenderer()

    renwin = vtk.vtkRenderWindow()

    # An interactor
    interactor = vtk.vtkRenderWindowInteractor()

    # A Sphere widget
    sphereWidget = vtk.vtkSphereWidget()

    # Connect the event to a function
    sphereWidget.AddObserver("TapEvent", sphereCallback)
    sphereWidget.AddObserver("MiddleButtonPressEvent", sphereCallback)
    sphereWidget.AddObserver("RightButtonPressEvent", sphereCallback)
    sphereWidget.AddObserver("LeftButtonPressEvent", sphereCallback)
    sphereWidget.AddObserver("MouseWheelForwardEvent", sphereCallback)
    sphereWidget.AddObserver("MouseWheelBackwardEvent", sphereCallback)

    sphereWidget.AddObserver("MouseMoveEvent", sphereCallback)
    sphereWidget.AddObserver("CursorChangedEvent", sphereCallback)

    sphereWidget.AddObserver("SelectionChangedEvent", sphereCallback)

    sphereWidget.AddObserver("SwipeEvent", sphereCallback)
    sphereWidget.AddObserver("LeftButtonDoubleClickEvent", sphereCallback)
    sphereWidget.AddObserver("MiddleButtonDoubleClickEvent", sphereCallback)
    sphereWidget.AddObserver("RightButtonDoubleClickEvent", sphereCallback)
    sphereWidget.AddObserver("MouseWheelLeftEvent", sphereCallback)
    sphereWidget.AddObserver("MouseWheelRightEvent", sphereCallback)

    # Start

if __name__ == '__main__':

As you can see I tried many different events but no Callbacks were printed when I clicked on the sphere created. Which events correspond to trackpad use?


The Tap, Swipe, etc. events are only available in C++ VTK programs that use Qt. For all other VTK programs, you must use the Button and Mouse events.

If you use PyQt (or PySide) and are feeling ambitious, you can add trackpad event handling to

Edit: I should add that DoubleClick events are also only for Qt.

Thanks for responding so quickly!

So, to be clear, using Python VKT, I can’t capture interactive trackpad events like I can with mouse clicks and buttons?

That’s correct. The only events you will get from the trackpad are mouse events.


You can use the VTK render widget provided by CTK in Python. This widget can handle macOS touchpad events and Windows touchscreen events.

The only inconvenience is that CTK is not available on PyPI but you need to build it locally or use a Python environment where it is made available already, such as in 3D Slicer.

See how the ctkVTKRenderView class works in 3D Slicer: