Search code examples
colorspygtk

PyGtk3: Get current Entry text color


I currently have the following in my PyGtk3 program that changes the Entry text color to red if the input is not acceptable:

...
self.entryIpAddress = Gtk.Entry()
self.entryIpAddress.connect('changed', self.entryIpAddress_changed)
...

def entryIpAddress_changed(self, widget):
   if not valid_ip_address(self.entryIpAddress.get_text()):
      self.entryIpAddress.override_color(Gtk.StateFlags.NORMAL, Gdk.RGBA(1.0, 0.0, 0.0, 1.0))

This works, but I want to return the text back to it's original color. Is there a method I can use to find out what the Entry's text color is before I start changing it?


Solution

  • After some more searching, I found out how to do it:

    style = self.lblIpAddress.get_style_context()
    self.entryIpDefaultColor = style.get_color(Gtk.StateType.NORMAL)