#!/usr/bin/perl use strict; use warnings; use Tk; my $mw = MainWindow->new; my $entry = $mw->Entry()->pack; my $entry1 = $mw->Entry()->pack; my $entry2 = $mw->Entry()->pack; autofocus($_) for ($entry, $entry1, $entry2); sub autofocus { my $widget = shift; $widget->bind( '' => sub{ $widget->focus } ); } MainLoop;