WX 加shortcut

#!/usr/bin/env python

import wx
 
class MyForm(wx.Frame):
 
    #----------------------------------------------------------------------
    def __init__(self):
        wx.Frame.__init__(self, None, wx.ID_ANY, "Tutorial", size=(500,500))
 
        # Add a panel so it looks the correct on all platforms
        panel = wx.Panel(self, wx.ID_ANY)
 
        randomId = wx.NewId()
        self.Bind(wx.EVT_MENU, self.onKeyCombo, id=randomId)
        accel_tbl = wx.AcceleratorTable([(wx.ACCEL_CTRL,  ord('Q'), randomId )])
        self.SetAcceleratorTable(accel_tbl)
 
    #----------------------------------------------------------------------
    def onKeyCombo(self, event):
        """"""
        print "You pressed CTRL+Q!"
 
# Run the program
if __name__ == "__main__":
    app = wx.App(False)
    frame = MyForm()
    frame.Show()
    app.MainLoop()

WX 在Frame上在加上shortcut

A typical example of an event not propagated is the wx.EVT_KEY_DOWN. It is send only to the control having the focus, and will not propagate to its parent.

To see what is happening have a look at the following example and play with it. Just set some different propagation levels in the OnKeyText method and see what happens. 

上面這一段的意思是在wx裡隻有有焦點的控件才會產生wx.EVT_KEY_DOWN,而且不為傳給parent,

有一問題是:那frame、panel的wx.EVT_KEY_DOWN事件有什麼用?



你可能感兴趣的:(WX 加shortcut)