【问题标题】:Unbind default button behavior in wxPython取消绑定 wxPython 中的默认按钮行为
【发布时间】:2013-07-19 03:46:11
【问题描述】:

我正在编写一个界面,我想让用户单击一个按钮,然后捕获他的下一次击键。

我目前可以捕获键盘上的所有键,但制表键或箭头键等会导致按钮在按下时失去焦点的键除外。我知道我需要在捕获间隔期间解除窗口与按键事件的绑定。

我已经尝试从框架、笔记本标签小部件和其中的面板取消绑定,但没有成功。

我需要在层次结构中的哪个位置取消绑定按键以避免它们的行为方式与通常的方式相同? 谢谢

【问题讨论】:

    标签: python events user-interface binding wxpython


    【解决方案1】:
    import wx 
    
    a = wx.App(redirect=False)
    class XFrame(wx.Frame):
        def __init__(self,*args):
            wx.Frame.__init__(self,*args)
            b = wx.Button(self,-1,"Click")
            b.Bind(wx.EVT_BUTTON,self.OnButton)
        def OnButton(self,evt):
            self.SetFocus()
            self.Bind(wx.EVT_CHAR,self.OnChar)
        def OnChar(self,evt):
            print evt.KeyCode
            self.Unbind(wx.EVT_CHAR)
    
    f = XFrame(None,-1,"A Frame")
    
    f.Show()
    a.MainLoop()
    

    我觉得还是

    【讨论】:

    • 哈!我从来没有想过将按键事件绑定到窗口本身。谢谢!我的代码已经过修改,现在运行良好。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-04-20
    • 2014-06-29
    • 1970-01-01
    • 2018-07-20
    • 2012-05-16
    • 2011-06-25
    • 1970-01-01
    相关资源
    最近更新 更多