Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>While Chris is right about "\t" indenting the keybinding correctly in the menu, I don't really see what he means by <em>automatically</em> associating anything using an ampersand. The ampersand (&amp;) DOES allow the used to type ALT to get the File menu to open and then if you type another letter that has had the ampersand applied to it, it will jump to that menu item, but the &amp; does not connect the menu item to the accelerator table. That is done via the menu item's ID.</p> <p>See the following code:</p> <pre><code>import wx ######################################################################## class MyForm(wx.Frame): #---------------------------------------------------------------------- def __init__(self): wx.Frame.__init__(self, None, wx.ID_ANY, "wx.Menu Tutorial") self.panel = wx.Panel(self, wx.ID_ANY) menuBar = wx.MenuBar() fileMenu = wx.Menu() exitId = wx.NewId() exitMenuItem = fileMenu.Append(exitId, "&amp;Exit/tCtrl+X", "Exit the application") self.Bind(wx.EVT_MENU, self.onExit, id=exitId ) menuBar.Append(fileMenu, "&amp;File") self.SetMenuBar(menuBar) accel_tbl = wx.AcceleratorTable([(wx.ACCEL_CTRL, ord('X'), exitId )]) self.SetAcceleratorTable(accel_tbl) #---------------------------------------------------------------------- def onExit(self, event): """""" self.Close() # Run the program if __name__ == "__main__": app = wx.App(False) frame = MyForm().Show() app.MainLoop() </code></pre> <p>Note that the <strong>exitId</strong> is used to create the menu item, bind the menu item to EVT_MENU and finally, it is used in the AcceleratorTable so the user can use the shortcut key.</p> <p>Here are a few references that might be helpful:</p> <ul> <li><a href="http://www.blog.pythonlibrary.org/2008/07/02/wxpython-working-with-menus-toolbars-and-accelerators/" rel="nofollow">http://www.blog.pythonlibrary.org/2008/07/02/wxpython-working-with-menus-toolbars-and-accelerators/</a></li> <li><a href="http://wiki.wxpython.org/WorkingWithMenus" rel="nofollow">http://wiki.wxpython.org/WorkingWithMenus</a></li> <li><a href="http://zetcode.com/wxpython/menustoolbars/" rel="nofollow">http://zetcode.com/wxpython/menustoolbars/</a></li> <li><a href="http://www.blog.pythonlibrary.org/2010/12/02/wxpython-keyboard-shortcuts-accelerators/" rel="nofollow">http://www.blog.pythonlibrary.org/2010/12/02/wxpython-keyboard-shortcuts-accelerators/</a></li> </ul>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload