使用gtk3,如何更改默认的GtkWindow标题栏颜色?它会涉及GtkStyleContext吗?我只使用过GtkCssProvider。
答案 0 :(得分:2)
您无法从GTK更改标题栏颜色。标题栏由窗口管理器绘制,GTK不会“知道”任何有关它的内容。您只能通过“提示”与窗口管理器进行通信,例如窗口是否应该有标题栏或者应该在那里显示哪个字符串,但窗口管理器可以自由忽略它们。
答案 1 :(得分:2)
您可以做到... (至少在Linux上) 发生的是,您的窗口未装饰,然后用标题栏“装饰”(恰好有一个血腥的“ show_close_button”,所以我想这是预期用途)
class base_ui(Gtk.Window):
def __init__(self):
# initializing self ( the window )
Gtk.Window.__init__(self, title="window title")
self.set_border_width(1)
self.set_default_size(800, 600)
# Create the header bar
hb = Gtk.HeaderBar()
# This is the id of the header bar to be used in the css file
hb.set_name("mw_hb")
# we can even set a close button ...
# you can add the other buttons as well, but have to do it yourself
hb.set_show_close_button(True)
# the effective text in the titlebar ( the window title )
# is props.title
hb.props.title = "win title"
# and here comes the sun - we set our headerbar as the new titlebar.
# Bazinga
self.set_titlebar(hb)