[vtkusers] Call Twice vtkTkRenderWidget in Python

Thinnes alexandre.thinnes at aist.go.jp
Mon Dec 20 18:59:24 EST 2004


Hello VTKusers,

I have some problems with management of many vtkTkRenderWidget.

I am developing GUI for surgical software in Python Language.
Each window of this GUI have one vtkTkRenderWidget to show 3D objects
(One of them use the vtkSliceWidget develop by Atamai).
I succeed to show one object into one window.
But if I try to open another one I get this error:

File "/usr/local/lib/python2.2/lib-tk/Tkinter.py", line 1316, in
__call__
    return apply(self.func, args)
  File "selection.py", line 64, in <lambda>
    command = lambda:
  File "functionclass.py", line 550, in entranceTriplan
    self.show2(self.triplan)
  File "functionclass.py", line 164, in show2
    self.affichageTriplan("exemple.mnc")
  File "functionclass.py", line 584, in affichageTriplan
    self.viewer1 =
vtkSliceWidget.vtkSliceWidget(self.triplan.frame1,width=256,height=256)
  File "/home/athinnes/atamai/examples/vtkSliceWidget.py", line 108, in
__init__
    Tkinter.Widget.__init__(self, master, 'vtkTkRenderWidget', cnf, kw)
  File "/usr/local/lib/python2.2/lib-tk/Tkinter.py", line 1780, in
__init__
    self.tk.call(
TclError: invalid command name "vtkTkRenderWidget"

This following is a simplify version of the software architecture
without using vtkSliceWidget .
Each module corresponding to one part of the interface ( Here there are
4 modules ):

######################################################################
#testfunc.py

from Tkinter import *
from vtkTkRenderWidget import *
import triplantest
import bouton
import render

class Functions:

   def __init__(self, myParent):
      print "functions class created"
# If you comment the self.render line. The button will open the
triplantest window
      self.render = render.Render(self, myParent)

      self.bouton = bouton.Bouton(self)
      self.triplan = triplantest.Triplan(self)

## Procedure:  show
# this procedure is call to show on the screen the windows winname
   def show(self, winname):
      winname.deiconify()
      self.affichageTriplan()

## Procedure:  affichageTriplan
# This procedure setup the slice image inside triplan interface

   def affichageTriplan(self):

      self.renderWidget = vtkTkRenderWidget(self.triplan.frame1)
      self.renderWidget.pack(expand='true',fill='both')


if __name__ == '__main__':

   root = Tk()
   function = Functions(root)
   function.triplan.withdraw()
   root.mainloop()

#######################################################################
#render.py

from vtkTkRenderWidget import *
from vtkpython import *
from Tkinter import *

class Render:

   def __init__(self, myFunctions, myParentFunction):

      self.functions = myFunctions
      myParentFunction.title("test vtkTkRenderWidget")

      self.viewer = Frame(myParentFunction, borderwidth = 2, relief =
"ridge")
      self.renderWidget = vtkTkRenderWidget(self.viewer)

      self.viewer.pack(expand='true',fill='both')
      self.renderWidget.pack(expand='true',fill='both')

##########################################################################

#triplantest.py

from Tkinter import *

class Triplan(Tk):
   def __init__(self, myFct):
      Tk.__init__(self)

      self.functions = myFct
      self.title("Frame for vtkSliceWidget")

      self.mainframe = Frame(self)
      self.frame1 = Frame(self.mainframe, relief="ridge", borderwidth=2)

      self.frame1.pack(expand='true',fill='both')
      self.mainframe.pack(expand='true',fill='both')

###############################################################
#bouton.py

from Tkinter import *
class Bouton(Tk):

   def __init__(self, myFunctions):
      Tk.__init__(self)
      self.functions = myFunctions
      self.title("Click On Button")
      self.frame = Frame(self)
      self.bouton = Button(self.frame, text = "click \nhere",
       command = lambda:
         self.functions.show(self.functions.triplan)
      )

      self.frame.pack(expand='true',fill='both')
      self.bouton.pack(expand='true',fill='both')

######################################################################3

If you run "python testfunc.py" you will see the error. It's the same I
have in the full software.

Somebody have any idea why it's not working and how to solve it?
It seams, vtkTkRenderWidget cannot be call twice. But I don't know how
to solve it.

Thank you for your attention
Best regards
Alexandre Thinnes




More information about the vtkusers mailing list