Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In PyGI (GTK3), how can I make a GtkEntry widget appear against the same background applied (by the user's theme) to the primary toolbar. I tried adding the same style class like this:


but that class doesn't seem to be observed on a widget that isn't a GtkToolbar. So how can I cue the user's theme to apply the same styles behind a GtkEntry widget?

(If it matters, I have the GtkEntry in the first cell of a GtkHBox container. But even when I apply a fixed gradient to that HBox the whole cell holding the GtkEntry seems to mask out the background of the HBox with a flat background colour.)


share|improve this question
You would need to add the class to the style context of the container of the entry, and not the entry itself. – dobey Aug 9 '12 at 21:27
Yes, but unfortunately the class doesn't do anything on non-toolbar widgets (e.g., an HBox or VBox). – monotasker Aug 12 '12 at 19:35
up vote 1 down vote accepted

It is called primary-toolbar style because it should be applied only to primary toolbar.

In Gtk, toolbars by default can hold only ToolButtons, but there is the ToolItem class, which does not have a visual represntation.

That is created because it can embed other widgets. ToolItem has add method which you can use like :

my_tool_item.add(my_box) where my_box contains your entry

Then you can add your tool item to toolbar my_toolbar.insert(my_tool_item,index)

Your toolbar of course has called : get_style_context().add_class(Gtk.STYLE_CLASS_PRIMARY_TOOLBAR)

The reason why you cannot use "primary-toolbar" with non Toolbar widgets is most probably because in .css files it is defined like :



    /* style info*/

share|improve this answer
Thanks @Aleksandar. I didn't realize that I would embed other widgets (aside from buttons) in a toolbar like this. It's kind of hidden in glade (which I'm using for ui design), but I finally realized that when I edit the widget hierarchy in glade for a GtkToolbar I can add a new item of the type "custom." That "custom" item type is the generic GtkToolItem. Then I was able to add my GtkEntry widget normally with glade's interface. – monotasker Aug 10 '12 at 23:06
No problem. I am glad to help. – Aleksandar Aug 11 '12 at 7:07

You did not say, why you can't use a toolbar, so I will suggest exactly that:

replace the HBox by a toolbar, give that toolbar the Gtk.STYLE_CLASS_PRIMARY_TOOLBAR style and you should be done...

share|improve this answer
Thanks for the suggestion, xubuntix. The trick was that I didn't know how to embed a GtkEntry widget in a toolbar. I've figured that out now, so I was able to use a toolbar after all. – monotasker Aug 10 '12 at 23:08

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.