(Excuse my english)
Hello! I'm new in the forum.
I'm a Python programmer and until a few days I was using GTK+2. Now, I'm learning GTK+3.
I like the idea to work with css files for styles.
My problem is that I can't change the background color of a GtkButton. I tryed a few examples I found on the web, but none work.
This is the code of one of them:
Code:
from gi.repository import Gtk, Gdk
class MainWindow(Gtk.Window):
def __init__(self):
super().__init__()
vbox = Gtk.Box(spacing=10,orientation=Gtk.Orientation.VERTICAL)
self.add(vbox)
self.entries = [ Gtk.Entry() for i in range(3) ]
for e in self.entries:
vbox.pack_start(e, True, True, 0)
e.connect("changed", self.on_entry_changed)
e.set_text('123')
button=Gtk.Button('ok',name='ok-button')
vbox.pack_end(button,True,True,0)
def on_entry_changed(self,entry):
ctx = entry.get_style_context()
if not entry.get_text().isnumeric():
ctx.add_class('invalid')
else:
ctx.remove_class('invalid')
cssProvider = Gtk.CssProvider()
cssProvider.load_from_path('style.css')
screen = Gdk.Screen.get_default()
styleContext = Gtk.StyleContext()
styleContext.add_provider_for_screen(screen, cssProvider,
Gtk.STYLE_PROVIDER_PRIORITY_USER)
window = MainWindow()
window.connect("delete-event", Gtk.main_quit)
window.show_all()
Gtk.main()
and the style.css
Code:
GtkEntry.invalid {
background-color: #ffaaaa;
background: #ffaaaa;
}
GtkButton#ok-button {
background-color: green;
background: green;
}
The entries works well... the bg color change. But the Button no, and theres no error messages.
I tryed also with
Code:
GtkButton {
background-color: green;
background: green;
}
I'm only can change the label properties with a css like this
Code:
GtkButton GtkLabe {
etc...
}
I'm using Python 3.2.3 and Kubuntu 12.10.
Thanks and greetings!