Change Gtk.Entry background color in Gtk3

I want to change the background color of my Gtk.Entry widget to red to show that there is an error in this field.

I found several ways to do this.

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

What is the right way to do this?

+4
source share
1 answer

You can use entry.override_background_color(Gtk.StateFlags.NORMAL, ...)(not override_bg()) or 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)
+5
source