Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Perk TK : Child Window widgets

by selva (Scribe)
on Jul 29, 2010 at 07:34 UTC ( #851864=perlquestion: print w/ replies, xml ) Need Help??
selva has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

I am facing problem in creating combo box widget in child window.

For first time, child window launching correctly and all widgets are placed fine. But for second time, when launching child window it doesn't show the Combo box widget

Kindly point me where is the problem

#!/usr/bin/perl use Tk; use Tk::JComboBox; my $screen_size = "1010x720+0+0"; my $tool_name='Testing Interface'; &Screen(); MainLoop; #-------Drawing User interface screeen---------------------- sub Screen { $main_screen_object = MainWindow->new(-bg => 'white'); $main_screen_object->geometry($screen_size); $main_screen_object->title($tool_name); createButton('CREATE NEW WINDOW',15,490,150,$main_screen_object); } #-------Callback function 'CREATE NEW WINDOW' button------------------ +------ sub onCREATENEWWINDOWButtonClick { $main_screen_object->update(); $CopyWindow=$main_screen_object->Toplevel(-height => 240, -width = +> 270, -background => 'white', -title => 'Copy Mapping') or die "coul +d not instant\n"; createLabel('COUNTRY',30,25,undef,undef,undef,$CopyWindow); our @CountryCodesList=qw /HD NK ID LK/; createComboBox('CountryCodes',10,140,25,$CopyWindow); } sub onCountryCodeComboBoxSelect { } #-------createLabel() - Used to create the label widget for given conf +iguration--------------- sub createLabel { my($LabelName,$x,$y,$background,$Font,$Foreground,$Object) = @_; $Font = 'verdana 10 bold' unless defined $Font; $background = 'white' unless defined $background; $Foreground = '#015F96' unless defined $Foreground; my($LabelNameObject); if ( defined($Object) ) { $LabelNameObject = $Object->Label(-background =>$background,-t +ext =>$LabelName,-font =>$Font,-foreground =>$Foreground)->place(-x=> +$x,-y=>$y); } else { $LabelNameObject = $main_screen_object->Label(-background =>$b +ackground,-text =>$LabelName,-font =>$Font,-foreground =>$Foreground) +->place(-x=>$x,-y=>$y); } return($LabelNameObject); } #-------createComboBox() - Used to create the combobox widget for give +n configuration--------------- sub createComboBox { my($ComboBoxName,$Width,$x,$y,$Object) = @_; $ComboBoxName =~ s/\s+//g; my $ComboBoxObject = $Object->JComboBox(-background =>'white', -textvariable => \${$ComboBoxName}, -choices => \@{$ComboBoxName."List"}, -browsecmd =>\&{"on".$ComboBoxName."ComboBoxSelect"} +, -font =>'verdana 10', -relief => 'solid', -borderwidth => 1, -entrywidth => $Width ) ->place(-x=>$x,-y=>$y) or die "Error $! \n\n"; return($ComboBoxObject); } #-------createButton() - Used to create the button widget for given co +nfiguration--------------- sub createButton { my($ButtonLabel,$Width,$x,$y,$Object) = @_; my($ButtonObject); my $ButtonName = $ButtonLabel; $ButtonName =~ s/\s+//g; $ButtonObject = $Object->Button(-background =>'grey', -text =>"$ButtonLabel", -font =>'verdana 10 bold', -foreground =>'black', -disabledforeground => '#90938D', -activebackground=>'#4A71AD', -activeforeground => 'white', -relief => 'solid', -borderwidth => 1, -width =>$Width, -command =>\&{"on".$ButtonName."Button +Click"})->place(-x=>$x,-y=>$y); return($ButtonObject); }

Comment on Perk TK : Child Window widgets
Download Code
Re: Perk TK : Child Window widgets
by Generoso (Vicar) on Jul 29, 2010 at 16:04 UTC

    ComboBox has a default value and it look like when this
    gets updated the object gets reset.
    Look at lines 50 to 56 that I changed and it is working.

    #!/usr/bin/perl use Tk; use Tk::JComboBox; my $screen_size = "1010x720+0+0"; my $tool_name='Testing Interface'; &Screen(); MainLoop; #-------Drawing User interface screeen---------------------- sub Screen { $main_screen_object = MainWindow->new(-bg => 'white'); $main_screen_object->geometry($screen_size); $main_screen_object->title($tool_name); createButton('CREATE NEW WINDOW',15,490,150,$main_screen_object); } #-------Callback function 'CREATE NEW WINDOW' button------------------ +------ sub onCREATENEWWINDOWButtonClick { $main_screen_object->update(); $CopyWindow=$main_screen_object->Toplevel(-height => 240, -width = +> 270, -background => 'white', -title => 'Copy Mapping') or die "coul +d not instant\n"; createLabel('COUNTRY',30,25,undef,undef,undef,$CopyWindow); our @CountryCodesList=qw /HD NK ID LK/; createComboBox('CountryCodes',10,140,25,$CopyWindow); } sub onCountryCodeComboBoxSelect { } #-------createLabel() - Used to create the label widget for given conf +iguration--------------- sub createLabel { my($LabelName,$x,$y,$background,$Font,$Foreground,$Object) = @_; $Font = 'verdana 10 bold' unless defined $Font; $background = 'white' unless defined $background; $Foreground = '#015F96' unless defined $Foreground; my($LabelNameObject); if ( defined($Object) ) { $LabelNameObject = $Object->Label(-background =>$background,-t +ext =>$LabelName,-font =>$Font,-foreground =>$Foreground)->place(-x=> +$x,-y=>$y); } else { $LabelNameObject = $main_screen_object->Label(-background =>$b +ackground,-text =>$LabelName,-font =>$Font,-foreground =>$Foreground) +->place(-x=>$x,-y=>$y); } return($LabelNameObject); } #-------createComboBox() - Used to create the combobox widget for give +n configuration--------------- sub createComboBox { my($ComboBoxName,$Width,$x,$y,$Object) = @_; $ComboBoxName =~ s/\s+//g; #--------------------------------------------------------- #--------------------------------------------------------- # the combobos list get update with the last select value # that is way I plased this line here and it is working my @combolist = @{$ComboBoxName."List"}; #--------------------------------------------------------- #--------------------------------------------------------- my $ComboBoxObject = $Object->JComboBox(-background =>'white', -textvariable => \${$ComboBoxName}, -choices => \@combolist, -browsecmd =>\&{"on".$ComboBoxName."ComboBoxSelect"} +, -font =>'verdana 10', -relief => 'solid', -borderwidth => 1, -entrywidth => $Width ) ->place(-x=>$x,-y=>$y) or die "Error $! \n\n"; return($ComboBoxObject); } #-------createButton() - Used to create the button widget for given co +nfiguration--------------- sub createButton { my($ButtonLabel,$Width,$x,$y,$Object) = @_; my($ButtonObject); my $ButtonName = $ButtonLabel; $ButtonName =~ s/\s+//g; $ButtonObject = $Object->Button(-background =>'grey', -text =>"$ButtonLabel", -font =>'verdana 10 bold', -foreground =>'black', -disabledforeground => '#90938D', -activebackground=>'#4A71AD', -activeforeground => 'white', -relief => 'solid', -borderwidth => 1, -width =>$Width, -command =>\&{"on".$ButtonName."Button +Click"})->place(-x=>$x,-y=>$y); return($ButtonObject); }

      Hi Generoso

      It is working fine. Thank you very much for your quick answer

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://851864]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (10)
As of 2014-09-16 23:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (51 votes), past polls