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

I'd like to use an equivelent to Window's combo box which combines an edit control and a drop-down list box. At present I'm using an Optionmenu, but it jars somewhat in a Windows environment and doesn't offer a combined edit control. I'd like to switch code similar to the sample code to use a combo box type control that had a rather more Windows look and feel.

use strict; use warnings; use Tk; my $main = MainWindow->new (-title => "Optionmenu demo"); my $id = 'Some different one'; my $IDLabel = $main->Label (-text => 'ID name: ', -anchor => 'w'); my $IDText = $main->Optionmenu ( -height => 1, -width => 40, -variable => \$id, ); $IDLabel->form (-left => '%0', -right => $IDText, -top => '%0'); $IDText->form (-right => '%100', -top => '%0'); $IDText->configure (-options => ['This one', 'That one', 'The other on +e']); MainLoop;

DWIM is Perl's answer to Gödel

Replies are listed 'Best First'.
Re: Tk equivelent of Window's combo box
by zentara (Cardinal) on Jun 10, 2006 at 11:00 UTC
    Try Rob Seegel's Tk::JComboBox
    #!/usr/bin/perl use warnings; use strict; use Tk; use Tk::JComboBox; my @choice = sort qw/Foo Bar Baz Red Green Blue Orange White Black/; my $chosen; my $mw = MainWindow->new(); $mw->Label( -text => 'Pick/type a value from JComboBox:' )->pack(); my $cb = $mw->JComboBox( -width => 15, -textvariable => \$chosen, -choices => \@choice, -maxrows => 5, -mode => 'editable', -validate => 'match', -relief => 'sunken', )->pack(); $mw->Label( -text => 'or just push this button:' )->pack(); $mw->Button( -text => 'Make a random choice', -command => sub { my $c = int( rand( scalar @choice ) ); print "$choice[$c] chosen at random\n"; $chosen = $choice[$c]; # uncomment the next line to fix errant JComboBox popup: # $cb->hidePopup(); } )->pack(); MainLoop;

    I'm not really a human, but I play one on earth. flash japh
Re: Tk equivelent of Window's combo box
by vkon (Curate) on Jun 10, 2006 at 12:16 UTC
    perl/Tk do not offer good drop-down box, it suggests poor substitute for it.

    There are some CPAN modules for it (Tk::JComboBox is an example) but it still do not solve problem

    Tcl/Tk offers much nicer comboboxes, even there is a possibility to use windows native widgets (with Tile extension), which could be used with the Tcl::Tk CPAN module.