wxPython - PlateButton 停止 wx.EVT_KEY_DOWN 事件

wxPython - PlateButton stopping wx.EVT_KEY_DOWN event

在我的应用程序中,当我按下 PlateButton 时,wx.EVT_KEY_DOWN 停止工作。我不知道发生了什么。如果我擦除 bmpImage 代码并将 PlateButton 的父级设置为自身,事件甚至不会首先触发。

谢谢!

import wx
import wx.lib.platebtn as pb

class MainFrame(wx.Frame):
    def __init__(self, parent):
        super().__init__(parent)

        self.initUI()
        self.Bind(wx.EVT_KEY_DOWN, self.OnKey)

    def initUI(self):
        bmpImage = wx.StaticBitmap(self, wx.ID_ANY)
        bmpImage.SetBitmap(wx.Bitmap('image.JPG', wx.BITMAP_TYPE_ANY))

        btn = pb.PlateButton(bmpImage, -1, 'Click Me!', style=pb.PB_STYLE_NOBG)

    def OnKey(self, event):

        print('Key pressed!')
        event.Skip()

app = wx.App()
frame = MainFrame(None)
frame.Show()
app.MainLoop()

如果你 运行 下面的代码,你会看到 platebutton 正在抓取事件并且显然没有跳过事件,因此它对你绑定到的框架不可用。

import wx
import wx.lib.platebtn as pb

class MainFrame(wx.Frame):
    def __init__(self, parent):
        super().__init__(parent)

        self.initUI()
        self.Bind(wx.EVT_KEY_DOWN, self.OnKey)

    def initUI(self):
        text = wx.StaticText(self, -1, "Key Test", pos=(10, 10))
        btn = pb.PlateButton(self, -1, 'Click Me!', pos=(10,40), size=(100,25))
        btn.Bind(wx.EVT_KEY_DOWN, self.OnKey)

    def OnKey(self, event):
        print(event.GetEventObject())
        print('Key pressed!')
        event.Skip()

app = wx.App()
frame = MainFrame(None)
frame.Show()
app.MainLoop()