wxPython按钮快捷方式加速器如何“垃圾邮件(&S)”

2024-09-28 20:56:46 发布

您现在位置:Python中文网/ 问答频道 /正文

我该如何添加按钮快捷键/加速器?在

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

在我的平台上似乎不起作用。在

^{pr2}$

找到的文章:

示例代码:

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时呈现。:(


Tags: selfhttptitleinitmaindefwxpythonbutton
1条回答
网友
1楼 · 发布于 2024-09-28 20:56:46

正如@RobinDunn所说,这是一个GTK配置。在

基本上将gtk-auto-mnemonics从0改为1。在

因为我使用的是XFCE4,所以我在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提前知道哪些“丑陋”按钮有加速器是很好的。在

或在GTK3中将gtk-auto-mnemonics从0更改为1:

^{pr2}$

无需按alt的结果:

enter image description here

相关问题 更多 >