Hello VTKusers,<br><br>I had a problem regarding the use of the vtkTkRenderWidget in Python.<br>After a bit of googling I found more people have had this problem, but<br>could not find a solution on the web. <br><br>I now found the solution myself, and thought to reply to the original poster<br>
(see message below). That post is from december 2004 (thus 4 years old).<br><br>Although the VTK version is different (I use VTK 5.21) the problem is the same.<br>The problem is cause by the function vtkLoadPythonTkWidgets in module<br>
vtk.tk.vtkLoadPythonTkWidgets. That function has the following lines near the <br>top, that prevent the widget to be found a second time:<br> <br> # find out if the file is already loaded<br> loaded = interp.call('info', 'loaded')<br>
if string.find(loaded, pkgname) >= 0:<br> pass#return <br><br>By simply replacing "return" with "pass" the problem is solved. <br><br>Cheers,<br> Almar<br><br><br>================ MESSAGE BY Alexandre Thinnes =============<br>
<br>I have some problems with management of many vtkTkRenderWidget.<br><br>I am developing GUI for surgical software in Python Language.<br>Each window of this GUI have one vtkTkRenderWidget to show 3D objects<br>(One of them use the vtkSliceWidget develop by Atamai).<br>
I succeed to show one object into one window.<br>But if I try to open another one I get this error:<br><br>File "/usr/local/lib/python2.2/lib-tk/Tkinter.py", line 1316, in<br>__call__<br> return apply(self.func, args)<br>
File "selection.py", line 64, in <lambda><br> command = lambda:<br> File "functionclass.py", line 550, in entranceTriplan<br> self.show2(self.triplan)<br> File "functionclass.py", line 164, in show2<br>
self.affichageTriplan("exemple.mnc")<br> File "functionclass.py", line 584, in affichageTriplan<br> self.viewer1 =<br>vtkSliceWidget.vtkSliceWidget(self.triplan.frame1,width=256,height=256)<br>
File "/home/athinnes/atamai/examples/vtkSliceWidget.py", line 108, in<br>__init__<br> Tkinter.Widget.__init__(self, master, 'vtkTkRenderWidget', cnf, kw)<br> File "/usr/local/lib/python2.2/lib-tk/Tkinter.py", line 1780, in<br>
__init__<br> self.tk.call(<br>TclError: invalid command name "vtkTkRenderWidget"<br><br>This following is a simplify version of the software architecture<br>without using vtkSliceWidget .<br>Each module corresponding to one part of the interface ( Here there are<br>
4 modules ):<br><br>######################################################################<br>#testfunc.py<br><br>from Tkinter import *<br>from vtkTkRenderWidget import *<br>import triplantest<br>import bouton<br>import render<br>
<br>class Functions:<br><br> def __init__(self, myParent):<br> print "functions class created"<br># If you comment the self.render line. The button will open the<br>triplantest window<br> self.render = render.Render(self, myParent)<br>
<br> self.bouton = bouton.Bouton(self)<br> self.triplan = triplantest.Triplan(self)<br><br>## Procedure: show<br># this procedure is call to show on the screen the windows winname<br> def show(self, winname):<br>
winname.deiconify()<br> self.affichageTriplan()<br><br>## Procedure: affichageTriplan<br># This procedure setup the slice image inside triplan interface<br><br> def affichageTriplan(self):<br><br> self.renderWidget = vtkTkRenderWidget(self.triplan.frame1)<br>
self.renderWidget.pack(expand='true',fill='both')<br><br><br>if __name__ == '__main__':<br><br> root = Tk()<br> function = Functions(root)<br> function.triplan.withdraw()<br> root.mainloop()<br>
<br>#######################################################################<br>#render.py<br><br>from vtkTkRenderWidget import *<br>from vtkpython import *<br>from Tkinter import *<br><br>class Render:<br><br> def __init__(self, myFunctions, myParentFunction):<br>
<br> self.functions = myFunctions<br> myParentFunction.title("test vtkTkRenderWidget")<br><br> self.viewer = Frame(myParentFunction, borderwidth = 2, relief =<br>"ridge")<br> self.renderWidget = vtkTkRenderWidget(self.viewer)<br>
<br> self.viewer.pack(expand='true',fill='both')<br> self.renderWidget.pack(expand='true',fill='both')<br><br>##########################################################################<br>
<br>#triplantest.py<br><br>from Tkinter import *<br><br>class Triplan(Tk):<br> def __init__(self, myFct):<br> Tk.__init__(self)<br><br> self.functions = myFct<br> self.title("Frame for vtkSliceWidget")<br>
<br> self.mainframe = Frame(self)<br> self.frame1 = Frame(self.mainframe, relief="ridge", borderwidth=2)<br><br> self.frame1.pack(expand='true',fill='both')<br> self.mainframe.pack(expand='true',fill='both')<br>
<br>###############################################################<br>#bouton.py<br><br>from Tkinter import *<br>class Bouton(Tk):<br><br> def __init__(self, myFunctions):<br> Tk.__init__(self)<br> self.functions = myFunctions<br>
self.title("Click On Button")<br> self.frame = Frame(self)<br> self.bouton = Button(self.frame, text = "click \nhere",<br> command = lambda:<br> self.functions.show(self.functions.triplan)<br>
)<br><br> self.frame.pack(expand='true',fill='both')<br> self.bouton.pack(expand='true',fill='both')<br><br>######################################################################3<br>
<br>If you run "python testfunc.py" you will see the error. It's the same I<br>have in the full software.<br><br>Somebody have any idea why it's not working and how to solve it?<br>It seams, vtkTkRenderWidget cannot be call twice. But I don't know how<br>
to solve it.<br><br>Thank you for your attention<br>Best regards<br>Alexandre Thinnes<br><br>