Re: Change label text color in Gtk 1+




On Apr 15, 2005, at 7:10 AM, David Morel wrote:

All I want is have an individual text label turn red in a window ! How
simpler can it get ? It would most certainly be so easy in GTK2+, but I
have no choice right now :-(

That's unfortunate. It's trivial in gtk2. You should port at the earliest opportunity.

Your problem is likely that the Gtk::Label is just inheriting its parent's style, and thus doesn't have one of its own for you to dork with. I can't seem to find a copy of this code that hasn't been ported to gtk2-perl, but it goes something like this:

# dupe parent widget's style -- a label isn't guaranteed to have one of its own
  my $newstyle = $window->get_style-copy;
  # set up the new style the way you want.
$font = Gtk::Gdk::Font->load ("-*-helvetica-bold-r-normal--*-120-*-*-*-*-*");
  $newstyle->font ($font);
  $newstyle->fg (0, $newcolor);  # labels draw text in fg color
  # explicitly tell the label to use this new style
  $label->set_style ($newstyle);

the new style object can be shared among all the labels you want to look the same.

--
The door is locked. I tried to open it, but the lock is harder to pick than a broken nose.
  -- Sensei, on 'I, Ninja'




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]