That means you want to modify the *label* inside the button:
import gtk
def click(b, *args):
label = b.get_child()
b.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("red"))
label.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse("green"))
def mainquit(*args):
gtk.main_quit()
def _test():
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
window.set_title("title")
window.connect("destroy", mainquit)
close = gtk.Button(label="press me!")
close.connect("clicked", click)
window.add(close)
window.show_all()
gtk.main()
if __name__ == "__main__":
_test()
On Mon, Oct 08, 2001 at 03:24:54PM -0500, Skip Montanaro wrote:
>
> Matt> On Mon, Oct 08, 2001 at 11:09:51AM -0500, Skip Montanaro wrote:
> >>
> >> gc = w.window.new_gc()
> >> color = gtk.gdk.color_parse("red")
> >> gc.set_foreground(color)
>
> Matt> You'd be surprised, but it's actually the background that you want
> Matt> to modify here.
>
> Matt> w.modify_bg(gtk.STATE_NORMAL, color)
>
> Yeah, I guess I would be surprised, since I was hoping to change the color
> of the text in the widget, not the background of the button. ;-) Calling
> modify_bg does change the background color of the button, but that's not
> quite what I was after.
>
> Maybe I should have phrased my question differently. How do I change the
> text color in a button? I thought that would have been covered by asking
> how to change the foreground color in a widget. Given this code:
>
> import gtk
>
> def click(b, *args):
> gc = b.window.new_gc()
> color = gtk.gdk.color_parse("red")
> b.modify_bg(gtk.STATE_NORMAL, color)
> color = gtk.gdk.color_parse("green")
> b.modify_fg(gtk.STATE_NORMAL, color)
>
> def _test():
> window = gtk.Window(gtk.WINDOW_TOPLEVEL)
> window.set_title("title")
> window.connect("destroy", gtk.mainquit)
>
> close = gtk.Button(label="press me!")
> close.connect("clicked", click)
> window.add(close)
>
> window.show_all()
>
> gtk.mainloop()
>
> if __name__ == "__main__":
> _test()
>
> after I click the button, when the button is in STATE_NORMAL, the background
> is red, however the text is still black.
>
> --
> Skip Montanaro ([EMAIL PROTECTED])
> http://www.mojam.com/
> http://www.musi-cal.com/
_______________________________________________
pygtk mailing list [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk