未调用Wxpython EVT_CHAR回调

2024-09-29 23:15:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个openglwxpython应用程序,我正试图在Ubuntu中运行。它是由其他人在macosx上开发的,在那里工作得很好。在

最后一个突出的问题是键盘事件没有被捕获。在

代码如下所示:

^{1}$

我已经为Bind调用修改了整个代码库,其他代码都没有使用EVT_CHAR、EVT_KET_DOWN或EVT_KEY_UP。我也尝试过EVT_KEY_DOWN和EVT_KEY_UP,但都不起作用。在

我也尝试过从

^{pr2}$

self.Bind(...)

这会中断EVT_运动,并且EVT_CHAR回调仍然不会被调用。在

在到达GLFrame之前是否有可能捕获键盘事件的调用?我是wxpython的新手,虽然这对我来说很有意义,但我肯定有一些我不知道的“陷阱”。在


Tags: key代码应用程序bindubuntu事件键盘macosx
2条回答

根据wxpython Google集团的调查,无论wx.框架接收键盘事件取决于实现。Ubuntu实现不接收它们。在

发件人:https://groups.google.com/d/msg/wxpython-users/dF2gf5KvFhE/M_-aRuG3aWUJ

Whether wx.Frames are able to catch key events is not defined by wx and therefore implementation dependent. The fact that it may work on some platforms is basically just a happy coincidence. I'm not sure about the GLCanvas class, but I would expect it to be able to if it has the focus. You may want to double check where the focus is at by doing something like "print wx.Window.FindFocus()" from a timer or something.

结果是,GLCanvas可以很好地接收键盘事件。不管是什么原因,它没有引起人们的注意。呼叫

self.canvas.SetFocus()

解决了这个问题。在

尝试绑定到框架而不是画布。。在

class GLFrame(wx.Frame):
    def __init__(self,*args,**kwargs):
        wx.Frame.__init__(self,*args,**kwargs)
        self.Bind(wx.EVT_MOTION, self.mouseMotion)
        self.Bind(wx.EVT_CHAR, self.character)


    def character(self, evt):
        print "EVT_CHAR"
        # do stuff

    def mouseMotion(self, evt):
        print "EVT_MOTION"

a = wx.App(redirect=False)
f = GLFrame(None,-1)
f.Show()
a.MainLoop()

相关问题 更多 >

    热门问题