When you say, "call another program" you need to be very careful when running a gui like Tk. Why? Because you will run into the problem of "blocking the gui". If you call "system some_other_perl_script", the tk gui will become unresponsive, while the cpu services the call, and runs the other script. So what you want to do is "fork and exec" and return the results in another window.

There is a very good module for doing this, called Tk::ExecuteCommand. Here is a basic example. You can do alot with this module, like pack it into different toplevel windows, instead of the mainwindow. A second example below does that. You can also change the appearance of the widget, by accessing it's "Advertised Subwidgets".

#!/usr/bin/perl use warnings; use strict; use Tk; use Tk::ExecuteCommand; my $mw = MainWindow->new; my $ec_dir = $mw->ExecuteCommand( -command => 'dir; sleep 10; dir;', -entryWidth => 50, -height => 10, -label => '', -text => 'Execute dir ', )->pack; my $ec_date = $mw->ExecuteCommand( -command => 'date; sleep 10; date;', -entryWidth => 50, -height => 10, -label => '', -text => 'Execute date ', )->pack; my $dir_but = $mw->Button( -text => 'Execute dir', -background => 'hotpink', -command => sub{ $ec_dir->execute_command })->pack; my $date_but = $mw->Button( -text => 'Execute date', -background => 'lightgreen', -command => sub{ $ec_date->execute_command })->pack; MainLoop;

For a separate toplevel:

#!/usr/bin/perl -w use Tk; use Tk::ExecuteCommand; use Tk::widgets qw/LabEntry/; use strict; my $mw = MainWindow->new; my $top = $mw->Toplevel; $top->withdraw; my $ec = $top->ExecuteCommand( -command => '', -entryWidth => 50, -height => 10, -label => '', -text => 'Execute', )->pack; $ec->configure(-command => 'date; sleep 10; date'); my $button = $mw->Button(-text =>'Do_it', -background =>'hotpink', -command => sub{ $top->deiconify; $top->raise; $ec->execute_command; $top->withdraw}, )->pack; MainLoop;

I'm not really a human, but I play one on earth. flash japh

In reply to Re: Open another Tk window by zentara
in thread Open another Tk window by perlNoob

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.