Perl

Code junkies hangout here

Moderators: ChrisThornett, LXF moderators

Perl

Postby bobthebob1234 » Fri Oct 01, 2010 5:15 pm

Why hello there.

I have been set an assignment to make a hangman game with perl and tk.

All is good, however when the user enters a letter and presses the enter key, nothing happens, they need to click on a button to get stuff to happen.

Here is some code
Code: Select all
...
# This is a text-userinput field
my $entryword = $main->Entry(
# width is in characters, not pixel
-width => 20)->place( -x => 440, -y => 175);
...
y $inputButton = $main->Button(-text => 'Take input', -state => "disabled",
-command => sub{sayhello()}
)->place(-x => 440, -y => 355 );
...

I want 'sayhello' to be run when the user has inputted a letter and presses enter.

Even better, the user can only input one letter and 'sayhello' is automatically run when then input one letter...

How would I go about doing this?

Thanks
For certain you have to be lost to find the places that can't be found. Elseways, everyone would know where it was
User avatar
bobthebob1234
LXF regular
 
Posts: 1372
Joined: Thu Jan 03, 2008 9:38 pm
Location: A hole in a field

Postby bobthebob1234 » Sun Oct 03, 2010 1:19 pm

Figured out the enter key bit.

Code: Select all
$main -> bind('<Return>', sub {sayhello()});


so simple.
For certain you have to be lost to find the places that can't be found. Elseways, everyone would know where it was
User avatar
bobthebob1234
LXF regular
 
Posts: 1372
Joined: Thu Jan 03, 2008 9:38 pm
Location: A hole in a field

Postby ScannerDarkly » Sun Nov 21, 2010 3:12 am

Perl's syntax makes my eyes bleed.

Oh sorry, thought this was a Python thread :D
Linux since Ubuntu 6.06.
ScannerDarkly
 
Posts: 30
Joined: Sat Jul 17, 2010 9:53 pm
Location: Cardiff


Return to Programming

Who is online

Users browsing this forum: No registered users and 2 guests

cron