0

Have a Gtk.Box() and need add specific css only to widget. Have a dinamic class as Box called CustomBox and have functions like setBackgroundColor(self, strRgbColor), need in each function modify the css only for that widget.

Example:

box1 = CustomBox()
box1.setPadding(10,10,0,0)

box2 = CustomBox()
box2.setBackgroundColor('#ff0000')

Need each widget with specific css.

Y have:

self.id = 'box_' + str(id(self))
box = Gtk.Box()
box.set_name(self.id)
# ...
css_provider = Gtk.CssProvider()
css_provider.load_from_data(('#' + self.id + '{ border: 1px solid red; }').encode())
context = Gtk.StyleContext()
# ... ??

Where self.id is the unique id (with id(self)), but how set the css_provider to box?

1 Answer 1

1

Use context.add_provider() to affect only the widget itself (not its children nor any other widgets) or Gtk.StyleContext.add_provider_for_screen() to affect all created widgets in your program.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.