Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GTK: create a colored regular button

How do I do it? A lot of sites say I can just call .modify_bg() on the button, but that doesn't do anything. I'm able to add an EventBox to the button, and add a label to that, and then change its colors, but it looks horrendous - there is a ton of gray space between the edge of the button that doesn't change. I just want something that looks like this:

img
(source: kksou.com)

The site claims to have just done modify_bg() on the button. But that doesn't work for me. =(.

The right answer probably involves creating a style, or something with a gtkrc file, etc. Can someone point me in that direction?

like image 592
Claudiu Avatar asked Aug 06 '09 19:08

Claudiu


People also ask

How do I change the color of my button on GTK?

Trying to change background/foreground color.... Using Gtk+ and C. GdkColor color; gdk_color_parse( "#0080FF", &color ); gtk_widget_modify_fg( GTK_WIDGET(button), GTK_STATE_SELECTED, &color ); gtk_widget_modify_fg( GTK_WIDGET(button), GTK_STATE_NORMAL, &color );

How do you change the color of a button in typescript?

In the ChangeColor() function, we call another function Change2(). This function is used to change the color of the button again.


1 Answers

Here's a little example:

import gtk

win = gtk.Window()
win.connect("destroy", gtk.main_quit)

btn = gtk.Button("test")

#make a gdk.color for red
map = btn.get_colormap() 
color = map.alloc_color("red")

#copy the current style and replace the background
style = btn.get_style().copy()
style.bg[gtk.STATE_NORMAL] = color

#set the button's style to the one you created
btn.set_style(style)

win.add(btn)
win.show_all()

gtk.main()
like image 197
JasonFruit Avatar answered Sep 23 '22 17:09

JasonFruit