Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Background color of Gtk.Entry in Gtk3

Tags:

python

gtk3

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?

like image 718
HappyHacking Avatar asked Jul 29 '14 14:07

HappyHacking


1 Answers

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)
like image 107
ptomato Avatar answered Nov 11 '22 19:11

ptomato