Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Thank your for your patience and help. I have improved the code a bit, but have hit a snag. I am using a hash reference to call a Checkbutton variable. The reference on line 55 , $flags{$tab} is the variable $pgr1_flag. Evidently this is ill-advised. Advice?
use warnings; use strict; use Tk; use Tk::NoteBook; require Tk::Pane; use Tk::LabEntry; my $mw = MainWindow->new; $mw->geometry( "600x500" ); $mw->title("Survival Kit"); ##mainwindow, scroll, frames## my $spane=$mw->Scrolled('Pane')->pack(-expand=>1,-fill=>'both'); my $frame1=$spane->Frame()->pack(-side=>'left',-expand=>1,-fill=>'both +',-padx=>15); my $frame2=$spane->Frame(-padx=>15)->pack(-side=>'right',-expand=>1,-f +ill=>'both'); ##Checkbuttons## my ($pgr1_flag,$pgr2_flag); my %flags = qw(program1 $pgr1_flag program2 $pgr2_flag); my $cb_cnt=1; for my $flag (keys %flags){ if ($cb_cnt < 6 ){ my $flag_but=$frame1->Checkbutton(-text => "$flag ", -variable + => \$flags{$flag} )->pack; } else { my $flag_but=$frame2->Checkbutton(-text => "$flag ", -va +riable => \$flags{$flag} )->pack; } $cb_cnt++; } ##OPEN button## my $open=$mw->Button(-text => "Open\n Tool (s)", -command => \&but)->p +ack( -side=>'bottom', -pady=>20); MainLoop; ####################### subs ################################# sub but { ## kill top window $spane->destroy($open); ###default hash my %tools = ( 'program1' => { 'PARM1' => 1, 'PARM2' => 'n', 'PARM3' => + 'y', 'PARM4' => 'n', 'PARM5' => 'y', 'PARM6' => 'n', 'PARM7' => 'y', + 'PARM8' => 'n', 'PARM9' => 'y', 'PARM10' => 'n' }, 'program2' => { ' +PARM1' => 1, 'PARM2' => 2, 'PARM3' => 3, 'PARM4' => 4, 'PARM5' => 5, +'PARM6' => 6, 'PARM7' => 7, 'PARM8' => 8, 'PARM9' => 9, 'PARM10' => 1 +0 }); ## create notebook my $book = $mw->NoteBook()->pack(-expand=>1,-fill=>'both'); #####program1####### my $tab_cnt=1; for my $tab (keys %flags){ if ($flags{$tab}){ ##create tab,scroll pane,frames my $tab_tab=$book->add("Sheet $tab_cnt", -label => "$tab")->pack +(-expand=>1,-fill=>'both'); my $tab_spane=$tab_tab->Scrolled('Pane')->pack(-expand=>1,-fill= +>'both'); my $tab_frame1=$tab_spane->Frame()->pack(-side=>'left',-expand=> +0,-fill=>'both',-padx=>15); my $tab_frame2=$tab_spane->Frame(-padx=>15)->pack(-side=>'right' +,-expand=>0,-fill=>'both'); $tab_cnt++; ##now fill frames my $parm_cnt=0; print "Processing tool: $tab\n"; foreach my $parm ( keys %{$tools{$tab}}) { print " $parm = $tools{$tab}{$parm}\n"; if ($parm_cnt < 5){ $tab_frame1->LabEntry(-label => "$parm=", -textvariab +le => "$tools{$tab}{$parm}" )->pack; } else { $tab_frame2->LabEntry(-label => "$parm=", -textvariab +le => "$tools{$tab}{$parm}" )->pack; } my $tab_parms .= "$parm=$tools{$tab}{$parm}\n"; $parm_cnt++; } } } ###################SAVE parameters? ## button - disappears on reset? #my $save1=$sub_spane->Button(-text => "Save Parameters ")->pack; ########Exit button########### ## Implement save? my $leave=$mw->Button(-text => "Save & Exit ",-command => \&save_parms +)->pack; ############################## #######Reset button############# ##needs better implementation? my $return=$mw->Button(-text => "Reset ", -command => \&rtn)->pack( -s +ide=>'bottom', -pady=>20); } ###################################################################### +###################################### sub rtn{ system 'perl doOver.1 &'; exit; } ############################# #our ($pgr1_parms,$pgr2_parms); sub save_parms { # open (SP1,">pgr1_parms.txt"); # print SP1 $pgr1_parms; # close SP1; # open (SP2,">pgr2_parms.txt"); # print SP2 $pgr2_parms; # close SP2; exit; }
BJ

In reply to Re^4: clunky Tk GUI by honyok
in thread clunky Tk GUI by honyok

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2024-04-24 12:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found