1

How do I change the colour of a button's text in Haskell (GTK)?

The code that I am using at the moment is:

button <- xmlGetWidget xml castToButton "buttonLabel"

Should I change the colour from within the program code, or I could do it in the XML as well?

scvalex
  • 14,931
  • 2
  • 34
  • 43
User3419
  • 1,716
  • 2
  • 14
  • 16

1 Answers1

3

Gtk2hs follows the GTK API very closely, so questions like this are best phrased without reference to Haskell.

I am basing my answer off the answer for the same question in C.

Basically, you have to change the colour of the widget (which is your button) with widgetModifyFg:

widgetModifyFg button StateNormal (Color 65535 0 0)

As to whether you should change the colour from code or XML, it depends. If you can, it's usually best to do it declaratively in XML; otherwise, just do it programatically in code.

Community
  • 1
  • 1
scvalex
  • 14,931
  • 2
  • 34
  • 43
  • thanks very much for your answer. I am completely unfamiliar with the GTK API, but the suggested piece of code did no change to the colour of my button at all. I think I must be doing something not the correct way. – User3419 Nov 30 '12 at 18:23
  • Do you want to change the colour of the button, or of its text? If you want the former, you should use `widgetModifyBg` instead. Also, could you provide a minimal example that demonstrates the problem? (maybe a few lines which create a button, change its colour, and demonstrate that the colour doesn't change) – scvalex Nov 30 '12 at 20:51
  • Apologies for the late reply here. I wanted to modify the colour of the text but I gave up (as I said, it did not work with the suggested line of code). The minimal example could be basically tested with the line provided above: `button <- xmlGetWidget xml castToButton "buttonLabel"` - just create any sort of Glade XML file that contains a button and assign it to `button`. For me, it resulted in no change. – User3419 Dec 07 '12 at 12:51