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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to use Perl/Tk in a perl module 1

Status
Not open for further replies.

wallythewhale

Technical User
Nov 5, 2002
14
US
Can some of the window be defined in a .pm? For example:

Versions.pm
use Tk;
sub CreateWin {
$mainWin = MainWindow->new();
...
$task_id_frame = $mainFrameData->Frame()->pack(-anchor => "w");
...
} # end sub CreateWin

Versions.pl
use Tk;
use Versions;
Versions::CreateWin;
$rbtnRv = $Versions::task_id_frame->Radiobutton(...
...
MainLoop();
...

I get this error:
Can't call method "Radiobutton" on an undefined value at...
 
Have you add:
Code:
package Versions;
at top of your Versions.pm ?

;-)
 
For general etiquette purposes,

Code:
$Versions::task_id_frame

Your Versions module should define global variables like this outside of any subroutines.

Code:
package Versions;

our $task_id_frame; # declare a global

use Tk;
sub CreateWin {
   $mainWin = MainWindow->new();
   ...
   $task_id_frame = $mainFrameData->Frame()->pack(-anchor => "w");
   ...
} # end sub CreateWin

It might just be easier in this case to actually write your own Tk:: module. Look at some of the other ones, so then your main program can just do this:

Code:
# versions.pl

use Tk;
use Tk::Versions;

# create the mainwindow for your main program, etc.
our $top = MainWindow->new (...)

# spawn the versions window
$top->Versions;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top