Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Perl/tk.. GUI's with perl

Status
Not open for further replies.

skottieb

Programmer
Joined
Jun 26, 2002
Messages
118
Location
AU
Hello all,
I am intrested in creating GUI's using perl code, I know it is possible, I even found SpecTcl, but have found it very limiting, Does any know of a GUI for making perl GUI's???? I am on a win 2000 box. skottieb:)
 
I don't think there is a GUI for making perl GUIs. I always use the perl/Tk kit since it can cross over to Linux / Unix without too much trouble.

You'll need the Tk module by Nick Ing-Simmons and if you get it from CPAN you'll also need nmake (Microsoft) to install it. There is a plethora of documentation with the module and creating GUIs is very easy if not sometimes a bit longwinded.

Something like;
use strict;
use Tk;

my $mw = MainWindow->new;
my $but = $mw->Button(-test => 'Hi there',
-command => sub {print "Hi There\n";});

$but->pack;

MainLoop;

This creates a small window with a button that prints the usual nice friendly greeting to the DOS window.

Enjoy.
 
I don't know of a GUI/IDE for making Perl GUI's, but,
you can make a Perl/Tk gui w/o a gui gui tool.

a trivial example,

Code:
#!perl
use Tk;
my $mw1 = MainWindow->new;
$mw1->configure(-title=>"a Tk window");
$mw1->geometry('400x30+100+00');

$mw1->Button(-text=>'Exit', 
             -command=>sub{exit})  
        ->pack(-side=>'top');

MainLoop;

A slightly more illustrative example that attaches a sub
routine to a button and changes the message on the first
window as the second window opens and closes.
Code:
#!perl
use strict;
use Tk;
my $message;
my $mw1 = MainWindow->new;
$mw1->configure(-title=>"perl GUI",
                -background=>'light grey');
$mw1->geometry('400x245+300+100');

my $fr1 = $mw1->Frame(  -relief=>'raised',
            -borderwidth=>2,
            -background=>'light grey')  
    ->pack(-side=>'top', -fill=>'x');

$fr1->Label(-textvariable=>\$message)
    ->pack(-side=>'left');

$fr1->Button(-text=>'Exit', 
             -command=>sub{exit})  
    ->pack(-side=>'right');
    
$mw1->Label(-text=>'Use this button to pop another window',
            -background=>'light grey')  
    ->pack(-side=>'top', -fill=>'x');

my $fr2 = $mw1->Frame(-relief=>'raised',
            -borderwidth=>2,
            -background=>'light grey')  
    ->pack(-side=>'top');

$fr2->Button(-text=>'Pop another window', 
             -command=>\&new_win )
    ->pack(-side=>'bottom');
MainLoop;
#----------------------------------------------------------
sub new_win
{
$message = "Popped a second window";
my $mw2 = MainWindow->new;
$mw2->configure(-title=>"perl GUI",-background=>'light grey');
$mw2->geometry('100x100+100+100');
$mw2->Button(-text=>'OK', 
             -command=>sub{ $mw2->destroy; 
                     $message = 'Closed the Window.'; } )
        ->pack(-side=>'bottom');
}
'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top