'Is there a way to automatically set the theme of a Gtk3 GUI according to system theme in Python?

I'm making a GUI for an Elementary OS app in Python, using Gtk3 for the GUI. I want to set the theme (light/dark/whichever theme is being used in Gnome) automatically according to the theme on the system. The documentation for Vala and demo program for Granite describes a way to do this:

var gtk_settings = Gtk.Settings.get_default ();
var granite_settings = Granite.Settings.get_default ();

gtk_settings.gtk_application_prefer_dark_theme = granite_settings.prefers_color_scheme == Granite.Settings.ColorScheme.DARK;

However, I can't seem to find any documentation in doing this in Python Gtk3+ (using from gi.repository import Gtk). Am I just missing something?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source