我应该如何添加按钮快捷键/加速器?
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()
结果:
直到现在,我才真正尝试热键,因为我并不是很好奇。
好的,所以当在这个例子中按alt+hot_key
为&垃圾邮件......它可以工作!
然而
热键字母最初没有加下划线。
下划线仅在按下alt时呈现。 :(
答案 0 :(得分:0)
正如@RobinDunn所说,这是一个GTK配置。
基本上将gtk-auto-mnemonics
从0更改为1.
由于我使用的是XFCE4,因此我在GTK2中启用了一个特定主题的助记符:
#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
可以提前了解它,而无需按下额外的按钮,其中“丑陋”按钮有加速器。
或者在GTK3中将gtk-auto-mnemonics
从0更改为1:
/usr/share/themes/CURRENT_THEME_NAME/gtk-3.0/settings.ini
无需按下alt即可获得结果: