Skip to main content
 首页 » 编程设计

python之如何在 mayavi 动画中捕捉键盘事件

2025年05月04日14JustinYoung

我正在寻找一种捕捉键盘事件的方法,以便在 mayavi 动画中循环浏览不同的数据集。

我的基本循环是:

while 1: 
    time = TIME() - zero 
    wx.Yield() 
    atomsanim[:,:3] = atoms[:,3:]*cos(speed*time) + atoms[:,:3] 
    f.scene.disable_render = True 
    atom_index = 0 
    for t, p in zip(types, plots): 
        ms = p.mlab_source 
        start = atom_index 
        stop = atom_index+t 
        ms.set(x=atomsanim[start:stop,0],y=atomsanim[start:stop,1],z=atomsanim[start:stop,2]) 
        atom_index += t 
    f.scene.disable_render = False 
 
mlab.show() 

请您参考如下方法:

谷歌搜索后我找到了这个页面:http://osdir.com/ml/python-enthought-devel/2009-01/msg00325.html

这几乎解决了我的问题

scene.interactor.add_observer('KeyPressEvent', your_function);  
def your_function(vtk_obj, event):  
 
... and then play with vtk_obj.GetKeyCode()