2014-04-13 15 views
1

我該如何去添加按鈕快捷方式/加速器?wxPython按鈕快捷方式加速器如何'&spam'

self.newItemButton = wx.Button(self.mainPanel, label='Scan &New Item') 

似乎無法在我的平臺上工作。

Python 2.7.3 (default, Sep 26 2013, 20:08:41) 
[GCC 4.6.3] on linux2 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import wx, os 
>>> wx.version();print(os.system('uname -a&&lsb_release -a')) 
'2.8.12.1 (gtk2-unicode)' 
Linux NE-522 3.2.0-53-lowlatency-pae #55-Ubuntu SMP PREEMPT Mon Aug 26 22:52:24 UTC 2013 i686 i686 i386 GNU/Linux 
No LSB modules are available. 
Distributor ID: Ubuntu 
Description: Ubuntu 12.04.3 LTS 
Release: 12.04 
Codename: precise 

文章實測值:

例如代碼:

import wx 
class SpamButton(wx.Frame): 
    def __init__(self, parent, title): 
     wx.Frame.__init__(self, parent, title=title) 
     self.mainPanel = wx.Panel(self) 
     self.thisSpamButton() 
     self.Show() 

    def thisSpamButton(self): 
      self.sizer = wx.BoxSizer(wx.VERTICAL) 
      #--------------------------------------------- 
      # So the letter 's' should be underlined right?  | Here it is 
      #-----------------------------------------------------v 
      self.newItemButton = wx.Button(self.mainPanel, label='&spam') 
      self.sizer.Add(self.newItemButton, 0, wx.ALL, 2) 
      self.mainPanel.Layout() 

def main(): 
    app = wx.App(False) 
    MainFrame = SpamButton(None, 'This Button Short Cut is weird') 
    app.MainLoop() 

if __name__ == '__main__': 
    main() 

結果:

Shouldn't the S be underlined?

更新:

我並沒有想的熱鍵,直到剛纔,只是因爲我沒有足夠的好奇。

好的,那麼當按alt+hot_key在這個例子&垃圾郵件......它工作!

但是:

熱鍵字母不是最初呈現下劃線。

下劃線僅在按下alt時呈現。 :(

+0

只是一個猜測,但是否顯示下劃線或不可能是默認關閉的GTK配置項目。他們幾年前做了與菜單項目圖標類似的事情。 – RobinDunn

+0

這可能是操作系統特定的問題。在Windows 8上,wxPython v3.0熱鍵字母加下劃線! –

+0

@RobinDunn感謝您的提示,終於想出了這一個。也感謝您的真棒和愛好者。 – jmunsch

回答

0

作爲@RobinDunn建議,這是一個GTK配置

由於我用XFCE4從0改變基本上以gtk-auto-mnemonics 1.

,我啓用助記符在GTK2爲這樣一個特定的主題:

enter image description here

#xfconf-query -c xsettings -p /Net/ThemeName 

#grab the current style/theme name 
VAR1=$(gconftool-2 --get /desktop/gnome/interface/gtk_theme) 
# change to that theme directory 
cd /usr/share/themes/$VAR1/gtk-2.0 
# replace gtk-auto-mnemonics = 0 with 'gtk-auto-mnemonics=1# = 0' 
sudo sed -i 's/gtk-auto-mnemonics/gtk-auto-mnemonics=1#/g' gtkrc 
# change the theme to something else ... (Clearlooks, Ambiance, some_theme) 
xfconf-query -c xsettings -p /Net/ThemeName -s Default 
xfconf-query -c xsettings -p /Net/ThemeName -s $VAR1 
#gconftool-2 --type=string -s /desktop/gnome/interface/gtk_theme ???? 

雖然他們的工作,按alt其漂亮的k現在不需要按下額外的按鈕,其中的'醜陋'按鈕具有加速器。

或者在GTK3變化gtk-auto-mnemonics從0到1:

/usr/share/themes/CURRENT_THEME_NAME/gtk-3.0/settings.ini 

結果,而不必按ALT:

enter image description here