# How to implement myself interactor in vtk pyqt?

**URL:** https://discourse.vtk.org/t/how-to-implement-myself-interactor-in-vtk-pyqt/2331
**Category:** Support
**Created:** [December 23, 2019, 3:16pm UTC](https://discourse.vtk.org/t/how-to-implement-myself-interactor-in-vtk-pyqt/2331 "2019-12-23T15:16:09Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![zhang-qiang-github](https://discourse.vtk.org/user_avatar/discourse.vtk.org/zhang-qiang-github/32/2519_2.png) [@zhang-qiang-github](https://discourse.vtk.org/u/zhang-qiang-github)
#### Post date: [December 23, 2019, 3:16pm UTC](https://discourse.vtk.org/t/how-to-implement-myself-interactor-in-vtk-pyqt/2331/1 "2019-12-23T15:16:09Z")

</div>

I need to start my own project. I want to implement my own interactor, and my code is:

> import vtk, sys
> 
> from vtk.qt.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor
> 
> from PyQt5.QtWidgets import \*
> 
> class myInteractorStyle(vtk.vtkInteractorStyleTrackballCamera):
> 
> ```
> def __init__ (self):
> super(myInteractorStyle, self). __init__ ()
> 
> def OnLeftButtonDown(self):
> super(myInteractorStyle, self).OnLeftButtonDown()
> print('left button down')
> 
> ```
> 
> class MainWindow(QMainWindow):
> 
> ```
> def __init__ (self, parent=None):
> super(MainWindow, self). __init__ (parent=parent)
> 
> self.frame = QFrame()
> 
> self.vl = QVBoxLayout()
> self.vtkWidget = QVTKRenderWindowInteractor(self.frame)
> self.vl.addWidget(self.vtkWidget)
> 
> self.ren = vtk.vtkRenderer()
> self.vtkWidget.GetRenderWindow().AddRenderer(self.ren)
> self.iren = self.vtkWidget.GetRenderWindow().GetInteractor()
> 
> # style = vtk.vtkInteractorStyleTrackballCamera()
> style = myInteractorStyle()
> self.iren.SetInteractorStyle(style)
> 
> # Create source
> source = vtk.vtkSphereSource()
> source.SetCenter(0, 0, 0)
> source.SetRadius(5.0)
> 
> # Create a mapper
> mapper = vtk.vtkPolyDataMapper()
> mapper.SetInputConnection(source.GetOutputPort())
> mapper.ScalarVisibilityOff()
> 
> # Create an actor
> actor = vtk.vtkActor()
> actor.SetMapper(mapper)
> actor.GetProperty().SetColor(1, 1, 1)
> actor.GetProperty().ShadingOff()
> 
> self.ren.AddActor(actor)
> 
> self.ren.ResetCamera()
> 
> self.frame.setLayout(self.vl)
> self.setCentralWidget(self.frame)
> 
> self.show()
> self.iren.Initialize()
> 
> ```
> 
> if **name** == “ **main** ”:  
> app = QApplication(sys.argv)
> 
> ```
> window = MainWindow()
> 
> sys.exit(app.exec_())
> 
> ```

I hope this code would print “left button down” when the left button clicked, but it don’t.  
What’s wrong with my project? Any suggestion is appraciated.
