[vtkusers] Zoom at start?

Slavko Kocjancic eslavko at gmail.com
Sun Feb 23 06:45:36 EST 2014


Hello...
I'm new to vtk and python. When I wrote some code to show sphere I get 
into trouble.
See example program...
When line #doMenuOpen()  is uncomented the sphere shous up and is all 
visible.
But if the line is commented (as is) and I click menu - open then sphere 
is totaly out of viewport.
How to solve that?

Thanks..\

and test code...
import sys
import Tkinter
import vtk
from vtk.tk.vtkTkRenderWidget import vtkTkRenderWidget

root = Tkinter.Tk()
renderWidget = vtkTkRenderWidget(root,width=400,height=400)
renderWidget.pack(expand='true',fill='both')
ren = vtk.vtkRenderer()
renWin = renderWidget.GetRenderWindow()
renWin.AddRenderer(ren)
menuBar = Tkinter.Menu(root)
root.config(menu=menuBar)

def doMenuFileExit():
     sys.exit(0)

def doMenuOpen():
     sphere = vtk.vtkSphereSource()
     sphereMapper = vtk.vtkPolyDataMapper()
     sphereMapper.SetInput(sphere.GetOutput())
     sphereActor = vtk.vtkActor()
     sphereActor.SetMapper(sphereMapper)
     renWin.AddRenderer(ren)
     ren.AddActor(sphereActor)
     renWin.Render()

#if you uncomment this line then sphere will fit into viewport
#doMenuOpen()

menuFile = Tkinter.Menu( menuBar, tearoff=0 )
menuFile.add_command( label='Exit', command=doMenuFileExit )
menuFile.add_command( label='Open', command=doMenuOpen )
menuBar.add_cascade( label='File', menu=menuFile )
root.mainloop()

#end


More information about the vtkusers mailing list