【发布时间】:2017-12-14 00:24:40
【问题描述】:
前言
在 gnome 3 应用程序中,一些按钮通过有色背景而不是普通按钮的灰色来突出显示。这些按钮不仅在使用标准 Adwaita 主题时颜色不同,而且在各种其他主题中也实现了。下面分别是 Adwaita 和 Flat Plat 主题的普通按钮和彩色按钮示例。
Adwaita
平板
现在我的问题
我希望能够在我的 Gtk3 应用程序中实现这些“重要按钮”。在研究如何做到这一点时,我在主题文件中发现这些“重要按钮”有一个特殊的 CSS 类,称为needs-attention。然后我尝试将按钮的 CSS 类也设置为 needs-attention。然而这并没有奏效。我仍然得到一个灰色的标准按钮。为了演示我所做的,我附加了一个最小的脚本和正在运行的程序的屏幕截图。 “重命名”按钮应该像上面的屏幕截图一样突出显示。我该怎么做?
我的代码
#!/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()
【问题讨论】:
标签: python button gtk3 gnome gnome-3