I have read something about CSS, but it seems me too complicated.
Please could anybody helsp me if exisst some similar (simple) soulutiol like for labes?
Thank you a lot
Use of CSS is not that easy for beginners, but it is the way GTK3 and GTK4 uses. There are reasons for that – e.g. as not only plain colors are used, but also gradients or pictures. But I know that often the first question of kids new to GTK was: How can I change this color – and they expected a simple command, and were disappointed when it was not possible with one plain command. But it is not too difficult, and I tried to explain it a bit in the book. I just tried to change the example from GTK4 for Graphical User Interfaces a little to color the window background, and it works fine. You can directly port that code to your C or C++, just use the long C names like gtk_button_new() instead of newButton() and so. And you should find more about CSS somewhere in the C API docs. Unfortunately CSS styling works not always so nice, I had use cases where my styling attempts just did not work.
import gintro/[gtk4, gobject, gio]
proc buttonCb(b: Button) =
echo "click"
proc activate(app: gtk4.Application) =
let window = newApplicationWindow(app)
let box = newBox(Orientation.horizontal, 10)
window.setChild( box)
let b1 = newButton("Click Me")
let b2 = newButtonWithMnemonic("_Mnemonic")
let b3 = newButtonFromIconName("document-print")
let b4 = newButton("\u2654")
let b5 = newToggleButton("Toggle Button")
let b0 = newButton("CSS Styled")
let cssProvider = newCssProvider()
let data = "window {color: yellow; background: green;}"
cssProvider.loadFromData(data)
let styleContext = window.getStyleContext
assert styleContext != nil
addProvider(styleContext, cssProvider, STYLE_PROVIDER_PRIORITY_USER)
for b in [b0, b1, b2, b3, b4, b5]:
box.append(b)
b.connect("clicked", buttonCb)
window.show
proc main =
let app = newApplication("org.gtk.example")
app.connect("activate", activate)
let status = app.run
quit(status)
main()
let data = "window {color: yellow; background: #ff00aa;}"
This #ff00aa would result in some purple background. It is RGB, red, green, blue, with ff=255 max value.
Other notations may work also, you may search with google for “CSS color values”.