in reply to Tk "hello, world", part 2

I prefer using -textvariable as Rhose++ pointed out, but if you really want to use ->get(), it needs to happen AFTER something is put into the Entry. Try this:

my $name; my $main = MainWindow->new(); $main->Label(-text=>"Company Name:")->pack(); my $entry = $main->Entry()->pack; $entry->focus(); $main->Button(-text=>"Continue", -command=> sub {$name = $entry->get() +; $main->destroy();})->pack(); $main->Button(-text=>"Cancel", -command => sub {exit})->pack(); $main->bind('<Return>' => sub {$main->destroy}); MainLoop; die "$name";

Also, next time, if you're going to include the error perl gave you, include all of the lines leading up to it. You can't have an error at line 38 of a 10 line script. . . :)

Replies are listed 'Best First'.
Re: Re: Tk "hello, world", part 2
by RandomWalk (Beadle) on Jan 29, 2004 at 21:31 UTC
    Thank you both.

    I guess I was using the get method as a way to see how MainLoop works. (Plus for a beginner there is comfort in having assignments isolated, explicit, and reference-free--but I'll just have to get used to the new syntax!)

    So it looks like I can't call the "get" method just once if I am to assign the entry text both upon button and return press. Right?