我一直致力于可视化生成的三维绘图玛雅维.mlab然后用Tkinter生成一个GUI窗口来改变3D绘图的一些参数(确切地说是2个)。我的问题是我无法将画布从Tkinter连接到我的mayavi绘图。更具体: 我为我的3D计算创建了一个类,为GUI创建了一个类。在
import numpy as np
from mayavi import mlab
from Tkinter import *
import tkMessageBox as msg
class 3Dplot_calc:
x,y,z = np.mgrid[-10:10:150j,-10:10:150j,-10:10:150j]
def __init__(self, R, I):
self.R = R
self.I = I
在这两者之间有一系列的方法来帮助计算有用的部分
^{pr2}$这就是我卡住的地方!!! GUI类继续为R和I定义滑块、其他一些按钮、绘图按钮并定义它们在框架中的位置。相关部分包括:
def Inputs(self,frame):
input_frame = Frame(frame)
input_frame.grid(column=0, row=0)
#Add Sliders
self.slR = Scale(input_frame, from_=1.0, to=5.0, orient=HORIZONTAL)
self.slR.set(1.0)
self.slI = Scale(input_frame, from_=-5.0, to=5.0, orient=HORIZONTAL)
self.slI.set(1.0)
#Add Plot Button
self.plot_button = Button(input_frame, text='PLOT', command = self.Generate_Values)
def Generate_Values(self):
R = int(self.slR.get())
I = float(self.slI.get())
a = 3Dplot_calc(R,I)
Bx,By,Bz = a.Bx, a.By, a.Bz #Those are the useful methods
field = mlab.pipeline.vector_field(Bx, By, Bz)
magnitude = mlab.pipeline.extract_vector_norm(field)
contours = mlab.pipeline.iso_surface(magnitude,contours=3)
field_lines = mlab.pipeline.streamline(magnitude, seedtype='line',
integration_direction='both')
self.canvas.show()
root = Tk()
gui = GUI(root)
root.mainloop()
3Dplot类本身运行良好。我得到的错误是:GUI实例没有属性“canvas”。 如果需要的话,我可以编辑帖子并放入我的完整代码。在
出于根本原因,我不认为这是可能的。一个程序只能有一个GUI后端运行事件循环,而IIUC,Mayavi的当前版本只支持Qt(well)和Wx(某种程度上)后端,而不支持Tkinter。我建议使用TraitsUI和Qt后端来改变参数,而不是TKinter。E、 g.见http://docs.enthought.com/mayavi/mayavi/auto/example_mayavi_traits_ui.html
相关问题 更多 >
编程相关推荐