Howdy,


I'm wondering about the following in my code:

1. My code barfs shortly after clicking on the "About..." Is it possible to make the Toplevel $tl modal (i.e. hold focus until the close button is depressed)? If so, how?

2. I've had to comment out strict because I'm not sure exactly how to pass the $mw from main to the sub do_toplevel. Can I safely use strict in a Tk program? If so, what syntax could I use to send $mw along?

#!perl -w =pod IP & Hostname GUI Program v .3 slojuggler =cut #use strict; use Socket; use Sys::HostIP; #For hostname use Sys::Hostname; my $ipaddr = hostip; print "Mine: $ipaddr \n"; my $hostnm = hostname(); print "Host $hostnm \n"; use Tk; my $mw = MainWindow->new; $mw->title("Your IP Info"); $mw->Label(-text=>"IP Address -> $ipaddr") ->pack(-fill => 'x', -side=>"top", -ipadx=>20); $mw->Label(-text=>"Hostname -> $hostnm") ->pack(-fill => 'x', -side=>"top"); $mw->Button(-text=>"Done!", -command=> sub { exit } ) -> pack (-side=> +"bottom"); #Somehow pass the $mw to the do_toplevel routine, to keep in step with + use strict #$mw->Button(-text=>"About...", -command=> \&do_toplevel + $mw arg som +ehow??? } ) -> pack (-side=>"bottom"); $mw->Button(-text=>"About...", -command => \&do_toplevel ) -> pack (-side=>"bottom +"); MainLoop(); sub do_toplevel { #Somehow pick up the $mw by using something like the following? #my $tl = shift or whatever it takes to bring in the passed in var +; ??? my $tl = $mw->Toplevel(); $tl->title("Aboutl"); $tl->Button(-text => "Close", - command => sub {$tl->destroy})->pack; $tl->waitWindow(); }

Thanks... --slojuggler


In reply to Modal Tk Toplevel/Passing a MainWindow by slojuggler

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.