A Tcl compatibility layer that emulates the classic VTK Tcl bindings (removed in VTK 8.2) by bridging VTK's Python API back into Tcl via tclpy.
The original VTK Tcl bindings allowed direct object creation and method calls using a natural Tcl syntax:
vtkCylinderSource cylinder
cylinder SetResolution 50
mapper SetInputConnection [cylinder GetOutputPort]This project restores that workflow by intercepting Tcl commands and dispatching
them to VTK through Python. It also provides a vtkTkRenderWidget command for
embedding VTK render windows inside Tk GUIs with interactive camera controls.
- Tcl 8.6+ (with Tk for GUI examples)
- Python 3 with VTK installed (
pip install vtk) - tclpy Tcl extension
Source the compatibility layer and use VTK as you would with the classic Tcl bindings:
source vtktcl.tcl
vtkCylinderSource cylinder
cylinder SetResolution 50
vtkPolyDataMapper mapper
mapper SetInputConnection [cylinder GetOutputPort]
vtkActor actor
actor SetMapper mapper
vtkRenderer ren
vtkRenderWindow renWin
renWin AddRenderer ren
vtkRenderWindowInteractor iren
iren SetRenderWindow renWin
ren AddActor actor
iren Initialize
renWin Render
iren StartEmbed a VTK render window in a Tk application:
source vtktcl.tcl
package require Tk
vtkRenderer ren
vtkRenderWindow renWin
renWin AddRenderer ren
vtkTkRenderWidget .vtk -width 600 -height 600 -rw renWin
pack .vtkThe widget supports mouse interaction (rotate, pan, zoom) out of the box.
VTK observers work with Tcl callbacks:
proc onKeyPress {} {
puts "Key pressed!"
}
iren AddObserver KeyPressEvent onKeyPress- vtktcl.tcl - The compatibility layer (source this to use VTK from Tcl)
- test_vtk.tcl - Basic rendering example with a cylinder
- test_vtk_observer.tcl - Observer/callback example
- test_vtk_tk.tcl - Full Tk GUI with sliders, color controls, and embedded VTK rendering
This project is licensed under the BSD 3-Clause License. See LICENSE for details.