By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,847 Members | 1,375 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,847 IT Pros & Developers. It's quick & easy.

Closing a menu window dynamically.

P: 40
Hi

I am having a problem in closing a menu window using TK module dynamically.

I use the following program.
Expand|Select|Wrap|Line Numbers
  1. use Tk;
  2.  
  3. $mw = MainWindow->new;
  4. $mw->geometry("1024x768");
  5. $mw->title("Menu Test");
  6.  
  7. $main_menu = $mw->Menu();
  8. $mw->configure(-menu => $main_menu);
  9. $file_menu = $main_menu->cascade(-label=>"File", -underline => 0, -tearoff=>0);
  10. $file_menu->command(-label=>"Exit", -underline=>0, -command=>sub{exit});
  11. $settings_menu = $main_menu->cascade(-label=>"Settings", -underline => 0, -tearoff=>0);
  12. $settings_menu->command(-label=>"Sub Menu1", -underline=>0, -command=>sub{&sub_func1});
  13. MainLoop;
  14. sub sub_func1
  15. {
  16.     $s_mw = MainWindow->new;
  17.     $s_mw->geometry("800x550+150+100");
  18.     $s_mw->title("Sub Menu");
  19.     $sub_menu1 = $s_mw->Menu();
  20.     $s_mw->configure(-menu => $sub_menu1);
  21.     $label1 = $s_mw->Label(-anchor => "w", -text => "Perl Path:", -background => "#D4D0C8", -cursor => "");
  22.     $txt1 = $s_mw->Entry(-borderwidth => 1, -cursor => "", -font => "Tahoma 8 normal", -foreground => "#000000", -relief => "sunken");
  23.  
  24.     $closeParent = $s_mw->Button(-background => "#FFFFFF", -borderwidth => 1, -text => "Close Main Window",-command => sub {&parent_close}, -cursor => "");
  25.     $cmdClear = $s_mw->Button(-background => "#FFFFFF", -borderwidth => 1, -text => "CLEAR",-command =>  sub{Clear()}, -cursor => "");
  26.     $cmdCancel = $s_mw->Button(-background => "#FFFFFF", -borderwidth => 1, -text => "EXIT",-command => [$s_mw => 'destroy'], -cursor => "");
  27.     $label1->place(-width => 96, -height => 24, -x => 25, -y => 25 );
  28.     $txt1->place(-width => 180, -height => 20, -x => 130, -y => 25);                
  29.  
  30.     $closeParent->place(-width => 100, -height => 20, -x => 200, -y => 500);
  31.     $cmdClear->place(-width => 60, -height => 20, -x => 350, -y => 500);
  32.     $cmdCancel->place(-width => 60, -height => 20, -x => 500, -y => 500);
  33.  
  34.     MainLoop;
  35. }
  36.  
  37. sub Clear 
  38. {
  39.     $txt1->delete(0, 'end');    $txt2->delete(0, 'end');
  40. }
  41.  
  42. sub parent_close
  43. {
  44. #Invoking close a window..
  45.     $mw => 'destroy'; 
  46. }
  47.  
I do know how to close a window dynamically in other menu...
looking any help regarding this.
Thanks
Jan 17 '08 #1
Share this Question
Share on Google+
1 Reply


P: 40
Hi.,

I found one the method to close a window..
Expand|Select|Wrap|Line Numbers
  1. $mw ->withdraw();
  2.  
Let me know if anyother method available.
Thanks,
Sabarish
Jan 17 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.