0
我試圖讓一些混亂的代碼通過CSS應用樣式,但我無法得到應用的樣式。這是不工作的代碼的一些例子:如何將CSS應用於雜亂的舞臺?
#!/usr/bin/python
from gi.repository import Clutter, GdkPixbuf, Cogl, Gtk, Gdk
Clutter.init([])
stage = Clutter.Stage()
stage.set_size(600, 300)
pixbuf = GdkPixbuf.Pixbuf.new_from_file('menu.svg')
pixel_format = Cogl.PixelFormat.RGBA_8888 if pixbuf.get_has_alpha() \
else Cogl.PixelFormat.RGB_888
image = Clutter.Image()
image.set_data(pixbuf.get_pixels(), pixel_format, pixbuf.get_width(),
pixbuf.get_height(), pixbuf.get_rowstride())
image_actor = Clutter.Actor()
image_actor.set_content_scaling_filters(
Clutter.ScalingFilter.TRILINEAR,
Clutter.ScalingFilter.LINEAR
)
image_actor.set_content(image)
image_actor.set_size(22,22)
image_actor.set_name("MyImage")
stage.add_child(image_actor)
css = """
#MyImage {
icon-shadow: red 0px 0px 30px;
background-color: #000000;
margin: 10px;
}
"""
style_provider = Gtk.CssProvider()
style_provider.load_from_data(css)
# This is the part that doesn't work
Gtk.StyleContext.add_provider_for_screen(
Gdk.Screen.get_default(),
style_provider,
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
)
stage.connect("destroy", lambda w: Clutter.main_quit())
stage.show()
Clutter.main()
我已經嘗試了幾種不同的東西,但風格從未得到應用。