My last puzzle is to create a small application in Python3 using GTK3 with colors other than the foggy ones on the buttons. The last few days I spent on the Internet searching for how to do this, and so far all that I tried has failed. Not just failed, but failed silently, without error messages, to let me know what was going on.
This is my test application:
from gi.repository import Gtk, Gdk class ButtonWindow(Gtk.Window): def __init__(self): super().__init__(title="Button Test") self.set_border_width(10) hbox = Gtk.Box(spacing=10) self.add(hbox) hbox.set_homogeneous(False)
I left my unsuccessful attempts as comments. As noted above, with regard to the application, it seems to have worked because none of the above options generate any error messages. However, none of them seem to work for me, because the buttons remain the color of outdated utensils.
FYI I am using Python 3.2.3 under Ubuntu 12.04 with python3-gi and python3-gi-cairo installed from a standard repository.
Can anyone point me in the right direction?
EDIT: The following is a reuse example based on @mike's answer. This works, but there are some problems with it, perhaps they will be discussed in some subsequent questions. Problems:
- Why should
background be used in Ubuntu instead of background-color , and then only for the button? - I still have problems setting up the fonts, but at least right now I have a working example for the game.
- You can use different styles / colors for different buttons, for example. based on text or some other attribute?
So the code: -
from gi.repository import Gtk, Gdk class ButtonWindow(Gtk.Window): def __init__(self): super().__init__(title="Button Test") self.set_border_width(10) hbox = Gtk.Box(spacing=10) self.add(hbox) hbox.set_homogeneous(False)
and the css file looks like this: -
GtkWindow { background-color: #0000ff; } GtkButton { color: #ff0000; background: #00ff00; }
I hope someone finds this helpful.