Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用python将CSS样式设置为GtkBox_Python_Css_Python 3.x_Pygtk - Fatal编程技术网

使用python将CSS样式设置为GtkBox

使用python将CSS样式设置为GtkBox,python,css,python-3.x,pygtk,Python,Css,Python 3.x,Pygtk,是否可以更改对象GtkBox的背景色?到目前为止,我在其他对象中使用的所有样式都很好,但GtkBox不适合我,你知道为什么吗?这是我的密码 self.Ventana = self.builder.get_object("ventana") self.Header= self.builder.get_object("header") self.Ventana.set_name('MyWindow') self.Header.set_name('header') self.style_provide

是否可以更改对象GtkBox的背景色?到目前为止,我在其他对象中使用的所有样式都很好,但GtkBox不适合我,你知道为什么吗?这是我的密码

self.Ventana = self.builder.get_object("ventana")
self.Header= self.builder.get_object("header")
self.Ventana.set_name('MyWindow')
self.Header.set_name('header')
self.style_provider = Gtk.CssProvider()
self.css=open(self.ruta+'/css/estilos.css','rb')
self.css_data = self.css.read()
self.style_provider.load_from_data(self.css_data)
Gtk.StyleContext.add_provider_for_screen(Gdk.Screen.get_default(),self.style_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)

/*********CSS STYLES *********/
#MyWindow {
    background-color: #1d1d1d;
}
/*i try whit: #MyWindow #header, #MyWindow GtkBox */
#header{
    background-color: #ffffff;
    border-bottom: 1px solid white;
}

问题是并非所有的gtk小部件都有自己的背景。然后,背景由底层小部件确定。对于gtk+3.12,此行为已更改

因此,更改Gtk.Box的背景色不适用于版本。如果您使用的是旧版本,另一种方法是在Gtk.Box下面使用Gtk.Viewport并更改视口的颜色

要将其转换为一些代码:

box = Gtk.Box()
viewport = Gtk.Viewport()
viewport.add(box)
#and the CssProvder, StyleContext,...
CSS:

GtkViewport {
    background-color: red;
)