#!/usr/bin/perl -w use strict; use warnings; use Tk; # Main program my $poe_main_window = new MainWindow(-title => 'Tk Binding example'); my $bg = "green"; my $psub = sub { new_toplevel($poe_main_window) }; my $text = "New Window ('c')"; my @args = (-bg => $bg, -command => $psub, -text => $text); my $button = $poe_main_window->Button(@args)->pack(); $poe_main_window->bind($poe_main_window, '', sub{ $button->invoke } ); MainLoop; # Subroutines sub new_toplevel { my ($mw) = @_; my $top = $mw->Toplevel(-title => "New TopLevel"); my $lbl = $top->Label(-bg => 'skyblue', -text => "Text Widget")->pack(); my $txt = $top->Text(-height => 16, -width => 120)->pack(); } #### $poe_main_window->bind($poe_main_window, '', sub{ $button->invoke } );