in reply to Tk MainWindow and another TopLevel spawn order
I played around a little bit: by changing forcing secondary_win to generate the phwin (your !Exists block) and by making $mw process one event, I was able to make the main window draw first and end up first in my Win7 application bar...
#!/usr/bin/perl use warnings; use strict; use Tk; use Tk::Pane; my $mw = new MainWindow (); $mw->title(" $0 MAIN"); my $phwin; # deleted '= $mw->Toplevel();': force it to be created by s +econdary_win() function my $fr0 = $mw->Frame(-borderwidth => 2, -relief => 'groove' )->pack(); $fr0->Label(-text => "MAIN $0 MAIN" )->pack(); $mw->DoOneEvent(); # appears to force mw to draw itself _before_ seco +ndary_win() creates phwin sleep(1); # makes it obvious that there's a delay; don't use + in production &secondary_win; MainLoop; ###################################################################### +########## sub secondary_win { # window does not exists if (! Exists($phwin)) { $phwin = $mw->Toplevel(); $phwin->title("SECONDARY"); } # window Exists else { $phwin->deiconify( ) if $phwin->state() eq 'iconic'; $phwin->raise( ) if $phwin->state() eq 'withdrawn'; } my $scrolledframe = $phwin->Scrolled('Frame',-scrollbars => 'osoe' +)->pack(); my $sec_label = $scrolledframe->Label(-text=>'SECONDARY')->pack; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Tk MainWindow and another TopLevel spawn order
by Discipulus (Canon) on Sep 21, 2016 at 08:05 UTC |