0

I'm trying to change the color of an entry gtk3 text. already searched everywhere and can not find a way. I think that is with an entry_buffer but I have no idea how to do it. for gtk2 found easily but my project is all in gtk 3. if anyone can help me I would appreciate.

CondeGil
  • 97
  • 11

1 Answers1

0

So there is this question How to make buttons different colours in Python GTK3 (using gi)? that you might find useful. One of the answers points to an article GTK+ 3 theme: style your applications that explains how you style gtk+ 3 applications in python. It looks like it's exactly what you need. The code below works on Ubuntu 12.04, I could not get it working on Ubuntu 11.04 so I assume you need a relatively recent version of these libraries to do this.

code

from gi.repository import Gtk, Gdk

window = Gtk.Window()
window.connect("destroy", Gtk.main_quit)
screen = Gdk.Screen.get_default()
css_provider = Gtk.CssProvider()
css_provider.load_from_path('style.css')
priority = Gtk.STYLE_PROVIDER_PRIORITY_USER
context = Gtk.StyleContext()
context.add_provider_for_screen(screen, css_provider, priority)
entry = Gtk.Entry(text='Testing..')
window.add(entry)
window.show_all()
Gtk.main()

style.css

GtkEntry {
    color: red;
    background: blue;
}

screenshot

enter image description here

Community
  • 1
  • 1
Marwan Alsabbagh
  • 25,364
  • 9
  • 55
  • 65
  • That answers my question completely. But I would like to know a way more versatile. I was wondering this because my intention was to make an entry with a default value and with a lighter color, but when it is used, change the color to black. As a way to set an example by default. – CondeGil Dec 01 '12 at 19:33
  • @user1794722 I know what you mean. Post another question, and you can describe that you want a text entry with a grey text hint in it that goes black when someone enters text into it. – Marwan Alsabbagh Dec 01 '12 at 19:36
  • @user1794722 When you post the other question just post a link to it here as a comment just for reference. – Marwan Alsabbagh Dec 02 '12 at 11:38