Re: selection dialog

Petr Pajas <[email protected]>
Newsgroups gmane.comp.lang.perl.tk
Organization UFAL MFF UK
Message-ID <[email protected]>
Dne Tuesday 12 July 2005 21:04 jste napsal(a):
> I need to make a dialog where it may contain 3+ values for the user to
> choose from (1 choice) and then they can either click Ok or Cancel.  I
> suppose this could be done either by radiobutton or highlighting.  Not
> sure if you can use radiobuttons inside a dialog box though, but I do
> need it to popup off the main window.   If someone has some sample code
> that could get me started I can handle the rest.

Something like the following? This is very basic pTk stuff (for which you can 
typically find examples in the widget demo).

#!/usr/bin/perl

use Tk;

$selected_color = 'Red';

$top = MainWindow->new;
$top->Button(-textvariable => \$selected_color, # reflect selected color
             -command => \&change_color
             )->pack;

sub change_color {
    my $d = $top->DialogBox(-title => "Pick a color", 
                            -buttons => ["OK", "Cancel"]);
    $d->Radiobutton(-text => $_,
                    -value => $_,
                    -foreground => lc($_),
                    -variable => \$selected_color)->pack() 
      for qw(Red Green Blue);
    $d->Show;
}
__END__

-- Petr
signature.asc (application/pgp-signature, 189 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)

iD8DBQBC1EH5QfxdLDi03+IRAhGvAJ4q9O340y4UwzsC0PNx/094yD3aKwCfdJpW
faE5GGhFoPyWT7tehH/zr3I=
=zeGW
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.