Ubuntu: How do I change GTK theme of my app in run time?


I recently noticed that monodevelop, can change GTK theme in runtime . How do I add it in my quickly app?


If you want, you can check out my Blog Post on Python, GTK and CSS

I tried to do a little write-up on how to do it (I used it for my quickly app as well).


You can use Gtk.CssProvidor to load a css file. For example:

css_provider = Gtk.CssProvider()  css_provider.load_from_file("file_name.css")  screen = Gdk.Screen.get_default()  style_context = window.get_style_context()  style_context.add_provider_for_screen(screen, css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)  

Where "file_name.css" is the css file you want to load (the themes in ubuntu seem to be in /usr/share/themes/THEME_NAME/gtk-3.0/) and window is the window widget you are using. If you want to load css from a string you can use css_provider.load_from_data(string_name.encode('UTF-8')) instead of css_provider.load_from_file("file_name.css")


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »