Another option, is to name your maindows in the other Tk scripts differently (like $mw1, $mw2,$mw3 , etc, then don't call MainLoop in those secondary windows, but do-one-loop manually. Its a bit more complex than fork-and-exec, but you asked for manual mainloop control.
#!/usr/bin/perl
use warnings;
use strict;
use Tk qw/tkinit DoOneEvent exit DONT_WAIT ALL_EVENTS/;
my $mw = tkinit;
$mw->Button(
-text => 'Test',
-command => sub { print "Pushed\n" },
)->pack();
$mw->Button(
-text => 'Quit',
-command => sub { Tk::exit(0) },
)->pack();
my $I;
while (1) {
$mw->DoOneEvent( DONT_WAIT | ALL_EVENTS );
if ( ++$I > 10000 ) { #slows things down use 1 for max speed
print '.';
$I = 0;
}
}
So instead of calling MainLoop in the secondary scripts, you do
sub manual_loop_control {
$mw1->DoOneEvent( DONT_WAIT | ALL_EVENTS );
$mw2->DoOneEvent( DONT_WAIT | ALL_EVENTS );
$mw3->DoOneEvent( DONT_WAIT | ALL_EVENTS );
}
in a timer in your main Tk script, like
$mw->repeat(10, \&manual_loop_control);
Using this method, you can even combine Gtk2 and Tk (any event loop script) and run them simultaneously.
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.