in reply to Tk focus

I'd like to run another program from my script. Both programs have a Tk interface.

There is your problem. What should have been a Tk::Dialog you've turned into another app.

Anyway, it works for me, and focusForce overrides the blinking taskbar behaviour on win32 (which I'm fond of, since I don't like apps to steal the focus from me)

#!/usr/bin/perl -- use strict; use warnings; use Tk; my $mw = tkinit(); $mw->Button( -text => 'go' , -command => sub { $mw->Busy; $mw->iconify; $mw->withdraw; system $^X, '-MTk', '-e', 'tkinit;MainLoop' ; $mw->raise; $mw->deiconify; $mw->update; $mw->focus; $mw->Unbusy; $mw->focus; $mw->focusForce; # win32 return; }, )->pack; MainLoop();

Replies are listed 'Best First'.
Re^2: Tk focus
by Beci (Initiate) on Jan 08, 2012 at 22:04 UTC

    Hi,

    This helped, the main app gets the focus back when the other exits.

    Thanks a lot for you and Khen1950fx also!

    Beci