Yeah, you have a tough bug in there, probably due to you trying to stuff too much into a dialogbox. First, to remove the small window, you can withdraw the mainwindow, and not use MainLoop. Thats easy.
The hard problem is that the Dialog dosn't seem to recognize global variables. I wonder if you really need to use a Dialog to put all that table data in there? Can't you just use the mainwindow or a toplevel? It may resolve the problem which I show in my modified version of your code. You can see, within the Dialog the values for my hash %be get printed, but it is not recognized elsewhere, like when you press the ShowValues button. That stumps me, and maybe a smarter monk may know the secret. :-)
If it was me, I would rewrite it without the Dialog.
#!/usr/bin/perl use strict; use warnings; use Tk; use Tk::DialogBox; use Tk::LabFrame; use Tk::Table; use Tk::BrowseEntry; my %be; #use a hash to store the BrowseEntry's stuff my $TKmain = MainWindow->new(); $TKmain->withdraw; #eliminates the small main window my $fontname = '-adobe-times-medium-r-normal--20-140-75-75-p-77-hp-rom +an8'; my $fontnameb = '-adobe-times-bold-r-normal--20-140-75-75-p-77-hp-roma +n8'; my @dropdownarray = ( 'Curly', 'Larry', 'Moe' ); my @layers = ( 'lyr1', 'lyr2', 'lyr3', 'lyr4', 'lyr5' ); my @scx = ( '1', '2', '3', '4', '5' ); #$TKmain->DialogBox(-title=>"Set Scales",-buttons=>["OK", "Cancel"]); +#redundant my $dlgSetScales = $TKmain->DialogBox(-title=>"Set Scales",-buttons=>[ +"OK", "Cancel"]); $dlgSetScales->resizable(0,0); $dlgSetScales->{SubWidget}{B_Cancel}->configure(-font=>$fontnameb,-bg= +>"firebrick"); $dlgSetScales->{SubWidget}{B_OK}->configure(-font=>$fontnameb,-bg=>"fo +restgreen"); my $f = $dlgSetScales->Frame()->pack(-fill=>'both'); $f->Label(-text=>"Set Scales",-font=>'-adobe-times-bold-r-normal--32-1 +00-75-75-p-57-iso8859-1')->pack(); my $table = $f->Table(-rows=>10, -columns=> 6, -scrollbars=>'e', -fixedrows=>1, -highlightbackground=>'black', -relief => 'raised', -fixedcolumns=>0, -takefocus=>1)->pack(-fill=>'x'); $table->put(0,0,$table->Label(-text=>" *Layer Name* ",-font=>$fontname +b,-bg=>"cadetblue")); $table->put(0,1,$table->Label(-text=>" *Scale X* ",-font=>$fontnameb,- +bg=>"mediumaquamarine")); $table->put(0,2,$table->Label(-text=>" *Scale Y* ",-font=>$fontnameb,- +bg=>"cadetblue")); $table->put(0,3,$table->Label(-text=>" *Factor X* ",-font=>$fontnameb, +-bg=>"mediumaquamarine")); $table->put(0,4,$table->Label(-text=>" *Factor Y* ",-font=>$fontnameb, +-bg=>"cadetblue")); $table->put(0,5,$table->Label(-text=>" *Map to Layer* ",-font=>$fontna +meb,-bg=>"mediumaquamarine")); my ($w,$cnt,%ScaleVal,$NewXScale,$NewYScale); my $xscale = 1.0002; my $yscale = 1.00018; $cnt = 1; foreach my $layer (@layers) { $ScaleVal{$layer} = {}; my $text = $layer; my $color = 'black'; $w = $table->Checkbutton(-text=>$text,-fg=>$color,-anchor=>'w',-va +riable=>\$ScaleVal{$layer}{CHECK},-font=>$fontname,-activebackground +=> "lightgoldenrodyellow"); $table->put($cnt,0,$w); $ScaleVal{$layer}{REALFACTORX} = $xscale; $ScaleVal{$layer}{REALFACTORY} = $yscale; $ScaleVal{$layer}{FACTORX} = sprintf("%0.06f",$xscale); $ScaleVal{$layer}{FACTORY} = sprintf("%0.06f",$yscale); $ScaleVal{$layer}{SCALEX} = sprintf("%0.01f",(($xscale-1)*12*1000) +); $ScaleVal{$layer}{SCALEY} = sprintf("%0.01f",(($yscale-1)*18*1000) +); #create labels w/ current scale $w = $table->Label(-textvariable=>\$ScaleVal{$layer}{SCALEX},-font +=>$fontname,-relief => 'groove'); $table->put($cnt,1,$w); $w = $table->Label(-textvariable=>\$ScaleVal{$layer}{SCALEY},-font +=>$fontname,-relief => 'groove'); $table->put($cnt,2,$w); $w = $table->Label(-textvariable=>\$ScaleVal{$layer}{FACTORX},-fon +t=>$fontname,-relief => 'groove'); $table->put($cnt,3,$w); $w = $table->Label(-textvariable=>\$ScaleVal{$layer}{FACTORY},-fon +t=>$fontname,-relief => 'groove'); $table->put($cnt,4,$w); # foreach my $dropdownlist (@dropdownarray) # { # $w->insert('end', $dropdownlist); # } $be{$cnt}{'var'} = $dropdownarray[0]; $be{$cnt}{'widget'} = $table->BrowseEntry( -label => "BE $cnt", -labelPack => [ -side => 'left', -anchor => 'w', -expand => 1, -padx => 4 ], -width => 20, -state => 'normal', -choices => \@dropdownarray, -variable => \$be{$cnt}{'var'}, -relief => 'groove' ); print $be{$cnt}{'var'},"\n"; print $be{$cnt}{'widget'},"\n"; $table->put($cnt,5, $be{$cnt}{'widget'} ); #next row $cnt++; } my $showbutton = $f->Button(-text => 'Show Values', -bg => 'white', -command => sub{ for (1..$cnt){ print $be{$cnt}{'var'},"\n"; print $be{$cnt}{'widget'},"\n"; print $be{$cnt}{'widget'}->Subwidge +t('entry')->Subwidget('entry'),"\n"; } })->pack(); $dlgSetScales->Show(); #MainLoop(); # to exit after Dialog close
In reply to Re^3: Multiple TK::BrowseEntry
by zentara
in thread Multiple TK::BrowseEntry
by mortbarsky
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |