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

I can successfully integrate a Checkbox in my popup menu (see below). It is possible to integrate Radiobuttons too? I am failing in this task.

sub Popup{ my ($mw, $obj) = @_; my $menu = $mw->Menu(-tearoff=>0, -menuitems=>[ [ checkbutton => "My Checkbox", -variable => \$var1, -onvalue => '1', -offvalue => '0', -compound => 'left', -command => [ sub { doSomething($var1) }, $obj ] ], ]); $obj->menu($menu); $obj->bind('<ButtonPress>', ['PostPopupMenu', Ev('X'), Ev('Y'), ]) +; return $obj; }

Replies are listed 'Best First'.
Re: Perl Tk Radiobutton in a popup menu
by choroba (Cardinal) on Mar 14, 2018 at 17:07 UTC
    Just include several radiobuttons that share the same variable to be grouped together:
    [ radiobutton => "My Radio1", -variable => \$var2, -command => sub { warn $var2 }, -value => 1, ], [ radiobutton => "My Radio2", -variable => \$var2, -command => sub { warn $var2 }, -value => 2, ],
    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
Re: Perl Tk Radiobutton in a popup menu
by Anonymous Monk on Mar 14, 2018 at 17:07 UTC
    You can create your own popup with a toplevel, then you can put anything you want into it.
    #!/usr/bin/perl use Tk; use strict; my ($mw, $dir); $mw = MainWindow->new(); $mw -> Button ( -text => "OK", -command => \&create_new) -> pack ( -side => 'left'); $mw -> Button ( -text => "Cancel", -command => sub {exit;}) -> pack ( -side => 'right'); MainLoop; sub create_new { my $mt = $mw -> Toplevel (-title => "first"); my $rb1 = $mt -> Radiobutton( -text => "one", -value => "one", -variable => \$dir) -> pack(-side => 'top', -fill => 'x'); my $rb2 = $mt -> Radiobutton( -text => "two", -value => "two", -variable => \$dir) -> pack(-side => 'top', -fill => 'x'); $mt -> Button ( -text => "OK", -command => [\&create_new2]) -> pack ( -side => 'left'); $mt -> Button ( -text => "Cancel", -command => sub {$mt -> destroy;}) -> pack ( -side => 'right'); } sub create_new2 { my $mf = $mw -> Toplevel(-title => "second"); $mf -> Button ( -text => $dir) -> pack ( -side => 'left'); $mf -> Button ( -text => "Cancel", -command => sub {$mf -> destroy;}) -> pack ( -side => 'right'); }