Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I went digging through a couple other application's code to find the answer. It turns out the default behavior with <code>\t</code> doesn't do what it <em>looks</em> like it would do (i.e. insert a tab character), but is sensibly interpreted by the toolkit as doing precisely what I wanted to do. Thus, the way to right-align a short cut is simple: create it with the text you desire, followed by <code>\t&lt;shortcut&gt;</code> (rather as I had above). In the example code I pasted above, if I wanted my shortcut to be <code>Ctrl + T</code>, it should therefore be thus:</p> <pre><code>menu = wx.Menu() item_id = 1 item_name = 'My menu item\tCtrl+T' help_text = 'Clicking this does something interesting.' item = menu.Append(item_id, item_name, help_text) </code></pre> <p><strong>Edit:</strong> updated the following section based on Mike Driscoll's <a href="https://stackoverflow.com/a/15554665/564181">very helpful answer</a>.</p> <p>Note that this creates the shortcut binding (wxPython picks that up), but it doesn't make it selectable using e.g. the Alt key on Windows.</p> <p>You can associate the Alt key to quickly open the menu and navigate to it by using the ampersand in your <code>item_name</code> text, but you'll still need to associate the desired keybinding manually via the <code>AcceleratorTable</code>:</p> <pre><code>menu = wx.Menu() item_id = 1 # Ctrl+T is bound to the keybinding accelerator_table = wx.AcceleratorTable([(wx.ACCEL_CTRL, ord('T'), item_id)]) self.setAcceleratorTable(accelerator_table) # Ctrl+T is not included, but the menu item can be accessed via Alt key item_name = '&amp;My menu item' help_text = 'Clicking this does something interesting.' item = menu.Append(item_id, item_name, help_text) </code></pre> <p>This, I imagine, would actually be the preferred pattern, as then anywhere that the <code>item_id</code> was referenced, the shortcut could be referenced automatically. This would also make for seamless updates.</p>
 

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