Question

I want to change the background color of my Gtk.Entry widget to red, to display that there's an error in this field.

I've found several methods how to accomplish this.

entry.modify_bg -> no change
entry.override_bg -> no change
entry.modify_base -> no change

Whats the correct way to do this?

Was it helpful?

Solution

You can use entry.override_background_color(Gtk.StateFlags.NORMAL, ...) (not override_bg()) or you can create some CSS:

provider = Gtk.CssProvider()
provider.load_from_data('.entry { background: red; }')
Gtk.StyleContext.add_provider_for_screen(Gdk.Screen.get_default(), provider,
    Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top