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

Fellow monks,

I'm having a bit of a problem finding any docs on this. I want to set the default on a radio button. This is my code thusfar:

$shape="square"; (stuff deleted) foreach ('square ', 'circle ', 'polygon'){ $frame2->Radiobutton( -bg=>COLOR, -activebackground=>COLOR, -text=>$_, -font=>'code14', -value=>$_, -variable=>\$shape, )->pack(-anchor=>'w'); }

My question is: Why isn't the radio button being set to square initiallly since I've set the variable? The radio buttons are being drawn fine, but with none selected.

All I can find in Mastering Perl/Tk is a reference to the default on a regular button. There is nothing listed in the reference charts in the back either. Have I missed something here?

Thanks!

Replies are listed 'Best First'.
Re: Default radio button in Tk
by ariels (Curate) on May 05, 2002 at 06:06 UTC

    You'll kick yourself.

    The value of $shape for setting a square is 'square  ', not 'square'.


    Update:

    Of course, the spaces in your list of names serve no purpose. You cannot (in general) use spaces to align text, because not all fonts are fixed-width. And since you're telling pack to anchor => 'w', you'll get the desired(?) left-justification anyway.

    Just say "foreach ('square','circle','polygon')" and have done with it...