'Close VTK window (Python)
Consider the following script
import vtk
ren = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
an_actor = vtk.... # create an actor
ren.AddActor(an_actor)
iren.Initialize()
renWin.Render()
iren.Start()
If the script ends there, everything is alright and the created window will be closed and the resources freed up when the window is closed manually (click X) or an exit key is pressed (Q or E).
However, if there are more statements, you will notice the window is still there, which is quite understandable since we haven't called anything to give it up, just ended the interaction loop.
See for yourself by appending the following:
temp = raw_input('The window did not close, right? (press Enter)')
According to VTK/Examples/Cxx/Visualization/CloseWindow, this
iren.GetRenderWindow().Finalize() # equivalent: renWin.Finalize()
iren.TerminateApp()
should get the job done but it doesn't.
What else do I have to do to close programatically the opened window?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
