mmartin has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,

I'm writing a front-end script for a Perl script I have, and I created a few RadioButtons. I was wondering
if it's possible to add a "Label" widget to a RadioButton?

I created the RadioButton, then tried using the set_label_widget() Method to add a Label I created and it
throws this error when I try to use it:
       Can't locate object method "set_label_widget" via package "Gtk2::RadioButton"


And if I simply try to use the Label widget's variable name as the RadioButton's text I see this instead of what the label
contains as its text when using the method new_with_label():
       Gtk2::Label=HASH(0x8614d54)


I read what documentation I found and I checked out the ManPage for Gtk2::RadioButton and couldn't find anything about using
Label Widgets with this. But I figured maybe it was possible since most of the documentation I found for Gtk2 doesn't always
show every single method that each particular widget is capable of using. For instance the info I found for some of the Widgets
don't include some of the methods like; "modify_bg()" and "modify_fg()", I found were missing from a few of the Widgets
Method's lists...


Any thoughts or suggestions would be much appreciated!

Thanks in Advance,
Matt

  • Comment on Perl::Gtk2 --- Possible for a RadioButton to contain a Label Widget?

Replies are listed 'Best First'.
Re: Perl::Gtk2 --- Possible for a RadioButton to contain a Label Widget?
by Loops (Curate) on Jun 25, 2013 at 19:01 UTC

    Not sure which documentation you're following, doesn't seem to be correct thought. The following works:

    use strict; use warnings; use Gtk2; Gtk2->init; my $window = Gtk2::Window->new ('toplevel'); my $bar1 = Gtk2::RadioButton->new (undef, 'Original Label'); $window->add ($bar1); $bar1->set_label('Updated Label'); $window->show_all; Gtk2->main;
Re: Perl::Gtk2 --- Possible for a RadioButton to contain a Label Widget?
by Ralesk (Pilgrim) on Jun 26, 2013 at 11:56 UTC
    I read what documentation I found and I checked out the ManPage for Gtk2::RadioButton and couldn't find anything about using Label Widgets with this. But I figured maybe it was possible since most of the documentation I found for Gtk2 doesn't always show every single method that each particular widget is capable of using. For instance the info I found for some of the Widgets don't include some of the methods like; "modify_bg()" and "modify_fg()", I found were missing from a few of the Widgets Method's lists...

    This is something that can be bothersome at first, but it’s actually useful. The widgets are organised into a hierarchy, and so, widget types deep in the hierarchy will have many methods inherited from higher up. Since everything visible is a Gtk2::Widget you should look at that man page too. Sometimes also somewhere inbetween (eg. Gtk2::Editable for Gtk2::Entry, or Gtk2::ToggleButton for Gtk2::RadioButton). These hierarchical relationships are written in every piece of documentation in the Gtk2 module.

    What’s slightly more annoying is the lack of explanations under the methods, so you’ll need to go to eg. GtkRadioButton and read their explanations there.

    As for the actual question about colouring: indeed, some widgets, including Gtk2::Label don’t have a full drawn area and they’re always transparent — you’ll need to wrap them in something that does, for example a Gtk2::EventBox. Then you’ll be able to colour the background of that and it will be visible through the Label.


    Update: Added link to GtkLabel rendering info.
Re: Perl::Gtk2 --- Possible for a RadioButton to contain a Label Widget?
by mmartin (Monk) on Jun 27, 2013 at 17:58 UTC
    Hey Guys, thank you both for the reply!

    Yea I decided to just use plain-text instead, orignally I was trying to use a "Gtk2::Label" as the RadioButton's label.
    I guess I was thinking "set_label()" was actually for adding a Label Widget... But I was wrong, Duhh lol...

    And yes Ralesk, your absolutely right about the documentation not having any good explanations for each Widget. If you
    go to the Sourceforge page for Perl::Gtk2 you'll see what I'm talking about. And when you check each object they only
    give you what Methods it has and what options go with those Methods, but no explanations at all. Which is EXACTLY the
    same information you see in each Widget's Manpage from the CLI...
            HERE--> http://gtk2-perl.sourceforge.net/doc/pod/index.html


    But anyway, I'm pretty much done with the aesthetics of the UI so I don't have to create anymore widgets... Finally...


    Thanks again Guys for the help and suggestions with this, much appreciated!



    Thanks Again,
    Matt