TransWikia.com

Detecting dark mode

Ask Ubuntu Asked by Garry Pettet on December 13, 2021

Is there a setting that can be read / polled to determine if the global Ubuntu dark mode is enabled or not by the user. I’m writing an app and would like to honour the user’s preference for my UI.

One Answer

This is not a fancy solution, but you can read the font color css value of e.g. some label. For dark themes this will (probably) be white(ish) and otherwise black. Same should be possible for backgroud-color and so on.

Python example:

tmp = self.label.get_style_context().get_color(Gtk.StateFlags.NORMAL)
textcolor = (tmp.red, tmp.green, tmp.blue, tmp.alpha)

Style Context docs

Answered by jl005 on December 13, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP