# BoxWidget

VTKExamples/Python/Widgets/BoxWidget

### Description

An example that shows how to use the BoxWidget to interactively scale and rotate and object.

Other Languages

See (Cxx)

### Code

BoxWidget.py

    import vtk

    # Call back function to resize the cone

    def boxCallback(obj, event):
        t = vtk.vtkTransform()
        obj.GetTransform(t)
        obj.GetProp3D().SetUserTransform(t)

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

        # Create a Cone
        cone = vtk.vtkConeSource()
        cone.SetResolution(20)
        coneMapper = vtk.vtkPolyDataMapper()
        coneMapper.SetInputConnection(cone.GetOutputPort())
        coneActor = vtk.vtkActor()
        coneActor.SetMapper(coneMapper)
        coneActor.GetProperty().SetColor(colors.GetColor3d("BurlyWood"))

        # A renderer and render window
        renderer = vtk.vtkRenderer()
        renderer.SetBackground(colors.GetColor3d("Blue"))
        renderer.AddActor(coneActor)

        renwin = vtk.vtkRenderWindow()
        renwin.AddRenderer(renderer)

        # An interactor
        interactor = vtk.vtkRenderWindowInteractor()
        interactor.SetRenderWindow(renwin)

        # A Box widget
        boxWidget = vtk.vtkBoxWidget()
        boxWidget.SetInteractor(interactor)
        boxWidget.SetProp3D(coneActor)
        boxWidget.SetPlaceFactor(1.25)  # Make the box 1.25x larger than the actor
        boxWidget.PlaceWidget()
        boxWidget.On()

        # Connect the event to a function
        boxWidget.AddObserver("InteractionEvent", boxCallback)

        # Start
        interactor.Initialize()
        renwin.Render()
        interactor.Start()

    if __name__ == '__main__':
        main()