I looked for an answer to this before posting, but I am not sure exactly what it is called that I am trying to do. I am writting a program using Tk. I would like to pass some of the Tk functions to packaged subroutines in a seperate .pm file, rather than putting everything in my main program. I am having a hard time passing a widget that was created in the main program into the .pm package. In the following code example, I would like to take the "subbie_1" subroutine and place it in a seperate .pm file. (I know I have to add all the handeling in the beginning I.E. require Exporter, etc). I just wanted to give an example of my problem.
use Tk;
# Main Window
my $mw = new MainWindow;
#GUI Building Area
my $frm_name = $mw -> Frame()->pack();
my $lab = $frm_name -> Label(-text=>"Name:")->pack(-side=>'left');
my $ent = $frm_name -> Entry(-textvariable=>\$entry_var)->pack();
$ent->bind('<Return>'=> \&subbie_1);
#Text Area
my $textarea = $mw -> Frame()->pack();
my $txt = $textarea -> Text(-width=>40, -height=>10)->pack();
MainLoop();
sub subbie_1
{
$txt->insert('end', "$entry_var\n");
}
How do I pass the $txt widget into a subroutine that is outside of the main program (seperate .pm file) so that I can call $txt->insert? My knowledge of Perl is still novice, so please be nice in responding. I have set up subroutines in the past, with little or no problem. However, I can't seem to get it to work with Tk.
Thoughts?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.