Hello. I have a perl/tk gui working to some degree of satisfaction, but this is my first attempt. I have successfully executed a program, however a problem occurs when the "program2" tab is selected and the window is resized. The tabs seem to disappear. Any ideas? -- The purpose is a simple front-end to several standalone programs which run from scripts. If there are any obvious flaws or pitfalls, please mention them.
#!/usr/bin/perl -w use warnings; use strict; use Tk; use Tk::NoteBook; require Tk::Pane; use Tie::IxHash; use Tk::LabEntry; my $mw = MainWindow->new; $mw->geometry( "600x500"); $mw->title("Survival Kit"); ##################NOTES######## ##expansion from 2nd tab has bug? ###default hash tie my %tools, 'Tie::IxHash', 'program1' => ordered_hash_ref ( 'PARM1' => 'Y', 'PARM2' => 'files', ' +PARM3' => 'list', 'PARM4' => 'Y', 'PARM5' => 'N'), 'program2' => ordered_hash_ref ( 'PARM' => '', 'PARM0' => 0, 'PARM1' = +> 1, 'PARM2' => 2, 'PARM3' => 3, 'PARM4' => 4, 'PARM5' => 5, 'PARM6' +=> 6, 'PARM7' => 7, 'PARM8' => 8, 'PARM9' =>9, 'PARM10' => 10 ); + ## create notebook my $book = $mw->NoteBook()->pack(-expand=>1,-fill=>'both'); #####program1####### my $tab_cnt=1; for my $tab (keys %tools){ ##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',-background=>'slate grey +')->pack(-expand=>1, -fill=>'both'); my $tab_frame1=$tab_spane->Frame(-background=>'blue')->pack(-sid +e=>'left',-expand=>1,-fill=>'both',-padx=>15); my $tab_frame2=$tab_spane->Frame(-background=>'red')->pack(-side +=>'bottom',-anchor=>'s',-fill=>'x'); $tab_cnt++; #create columns my $tab_column1 = $tab_frame1->Frame()->pack(-side=>'left',-exp +and=>1,-fill=>'both'); my $tab_column2 = $tab_frame2->Frame()->pack(-side=>'right',-ex +pand=>1,-fill=>'both'); ##now fill frames my $parm_cnt=1; #print "Processing tool: $tab\n"; foreach my $parm ( keys %{$tools{$tab}}) { #print " $parm = $tools{$tab}{$parm}\n"; my $tab_test; if ($parm_cnt < 7 ){ $tab_test=$tab_column1->LabEntry(-label => "$parm=" +); $tab_test->Subwidget('entry')->configure(-textvariable => + \$tools{$tab}{$parm} ); $tab_test->configure(-labelPack=>[-side=>'left']); $tab_test->pack(-anchor=>'e'); } else { $tab_test=$tab_column2->LabEntry(-label => "$parm=" +); $tab_test->Subwidget('entry')->configure(-textvariable => + \$tools{$tab}{$parm} ); $tab_test->configure(-labelPack=>[-side=>'left']); $tab_test->pack(-anchor=>'e'); } $parm_cnt++; } #######go and save button############# my $run=$tab_tab->Button(-text => "\n $tab \n ",-command=> +\&go ,-command =>[\&save_parms,$tab],-background=>'slate grey')->pack +; } MainLoop; ####################### subs ############################### ## save parameters ########## sub save_parms { my $tab = shift; #print $tab; open (my $parfile,"> ${tab}_parms.txt") or warn "$!\n"; foreach my $parm ( keys %{$tools{$tab}} ) { print $parfile "$parm=$tools{$tab}{$parm}\n"; } close $parfile; } ###########execute program sub go { #if ( "$tab" eq "program1"){ #open STDOUT,">tmpfile" or die "Cannot open temp file"; #open STDERR, '>>&STDOUT'; #system 'program1.exe' or die "$!\n" #close STDOUT; #} } ## order hashes## sub ordered_hash_ref { tie my %hash, 'Tie::IxHash', @_; return \%hash; } #######conflict between save_parms output and save_history output? #sub save_history { #foreach my $tool (sort keys %tools){ # open (my $histfile,"> ${tool}.history") or warn "$!\n"; # foreach my $text (custom_sort(\%{$tools{$tool}})) { # print $histfile "$text=$tools{$tool}{$text}\n"; # } #close $histfile; # } #} ###########################
Thanks. honyok

In reply to Tk gui bug by honyok

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.