Gtk3/Gnome 3 colored button: apply ".needs-attention" css styles
在 gnome 3 应用程序中,某些按钮通过有色背景而不是普通按钮的灰色背景突出显示。这些按钮不仅在使用标准 Adwaita 主题时颜色不同,而且在各种其他主题中也实现了。下面分别是 Adwaita 和 Flat Plat 主题的普通按钮和彩色按钮的示例。
阿德维塔
平板
现在我的问题
我也希望能够在我的 Gtk3 应用程序中实现这些"重要按钮"。在研究如何做到这一点的过程中,我在主题文件中发现这些"重要按钮"有一个名为
我的代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | #!/usr/bin/env python3 import gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk class ButtonWindow(Gtk.Window): def __init__(self): Gtk.Window.__init__(self, title="Needs Attention Button") self.set_border_width(10) hbox = Gtk.Box(spacing=6) self.add(hbox) button = Gtk.Button.new_with_label("Remove") hbox.pack_start(button, True, True, 0) button = Gtk.Button.new_with_mnemonic("Rename") button.get_style_context().add_class("needs-attention") hbox.pack_start(button, True, True, 0) win = ButtonWindow() win.connect("delete-event", Gtk.main_quit) win.show_all() Gtk.main() |
GNOME\\ 的 Adwaita 主题为建议的操作预定义了两个类:
-
suggested-action -
destructive-action
您可以在 GNOME Wiki HowDoI/Buttons 上阅读:
While most buttons are gray, it has become more fashionable to
emphasize buttons that are the suggested action, by giving them a
different color. In the Adwaita theme, the color is blue. ...
Recently, another style class for dangerous actions has been added as
well: 'destructive-action'. The Adwaita theme uses red for buttons
marked as such.
在 Adwaita 上,它们分别如下所示:
预定义的
The a€?needs-attentiona€? child property
1 a€?needs-attentiona€? gbooleanSets a flag specifying whether the child requires the user attention.
This is used by the GtkStackSwitcher to change the appearance of the
corresponding button when a page needs attention and it is not the
current one.
可以在
似乎我错的只是我使用了错误的 CSS 类。正确的是