O'Reilly logo

Mastering Perl/Tk by Nancy Walsh, Stephen Lidie

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The BrowseEntry Widget

BrowseEntry is a composite widget created to be like a combo box (also known as a drop-down listbox on some platforms) using an Entry widget, a Listbox, and a small arrow button. The combination of these three widgets in the BrowseEntry is very powerful.

Before we list the options and methods for a BrowseEntry, let’s look at an example:

use Tk; use Tk::ROText; use Tk::BrowseEntry; $mw = MainWindow->new(-title => "Text search using BrowseEntry"); # Create Browse Entry to enter search text in, and save off # already entered text that you've searched for. $f = $mw->Frame(-relief => 'ridge', -borderwidth => 2) ->pack(-fill => 'x'); # Use ROText so user can't change speech $t = $mw->Scrolled('ROText', -scrollbars => 'osoe') ->pack(-expand => 1, -fill => 'both'); $t->insert('end', <<'EOD' "Give Me Liberty or Give Me Death" March 23, 1775 By Patrick Henry No man thinks more highly than I do of the patriotism, as well as abilities, of the very worthy gentlemen who have just addressed the house. But different <snipped...> I know not what course others may take; but as for me, give me liberty or give me death! EOD ); # define a new tag to use on selected text # (making it look just like normal selection) # This way the Text widget doesn't need focus to show selection $t->tagConfigure('curSel', -background => $t->cget(-selectbackground), -borderwidth => $t->cget(-selectborderwidth), -foreground => $t->cget(-selectforeground)); my $search_string = ""; # If user selects ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required