The problem seems more complicated than it should be.
Apparently one of Raspberry's UI developers decided that it's not for people to be switching sources - see this post here:
link
And it is referenced by people who have had the same problem you are having (although programming in C).
They have managed to get around the problem - but the code to force another source is much more complicated, it is necessary to use the internal mechanisms of Gtk3 CSS - take the thread below and see the post of November 29, 2016 of PeterO: / p>
link
A variation of the program using gtk + CSS that works in Python on the computer is:
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk as gtk, Gdk as gdk
import tempfile, os
def setup():
window = gtk.Window()
# Aqui onde perdi mais tempo: nos exemplos usando glade, os
# seletores parecem ser "GtkTextView" e "GtkButton" -
# mas sem o glade são "textview" e "button" em minúsculas.
# (Também pode ser diferença na versão do GTK)
css = "textview {font-size: 24pt; color: #d0d0ff;}\n button {font-size: 40pt; color: #ff0000} "
# (a cor do textview não funcionou )
provider = gtk.CssProvider()
css_filename = tempfile.NamedTemporaryFile().name
with open(css_filename, "wt") as css_file:
css_file.write(css)
provider.load_from_path(css_filename)
# Existe o método "load_from_data", que no exemplo em C
# carrega uma string direto - mas em Python esse método
# não está funcionando, por isso o arquivo temporário
print(css_filename, provider.to_string())
# esse print certifica que o CSS foi lido e parseado:
# o GTK muda a formatação do whitespace
os.remove(css_filename)
frame = gtk.VBox()
window.add(frame)
text = gtk.TextView()
text.set_name("texto")
frame.pack_start(text, True, True, 6)
button = gtk.Button("Text test")
button.set_name("botao")
frame.pack_start(button, False, True, 6)
# aplica-se a styleshhet a toda a aplicação,
# em vez de um único widget.
screen = gdk.Screen.get_default()
context = gtk.StyleContext()
context.add_provider_for_screen(screen, provider, gtk.STYLE_PROVIDER_PRIORITY_USER)
window.connect("destroy", gtk.main_quit)
window.show_all()
def main():
gtk.init([])
window = setup()
gtk.main()