perlplayer has asked for the wisdom of the Perl Monks concerning the following question:

hello all, i want to create some buttons and interactive widgets from a toplevel window . i have written the code but its not working i saw in the documentation about -container and -use but i dont know how to use them..please help if there is any alternative method please suggest me
  • Comment on perl/tk...how to create interactive widgets inside toplevel window

Replies are listed 'Best First'.
Re: perl/tk...how to create interactive widgets inside toplevel window
by zentara (Cardinal) on Dec 05, 2008 at 15:24 UTC
    Container and -use are for specific uses, what exactly are you trying to do. Here are some ideas.
    #!/usr/bin/perl use warnings; use strict; use Tk; my $mw = MainWindow->new; $mw->title( "MainWindow" ); my $spawn_button = $mw->Button( -text => "Toplevel", -command => \&do_Toplevel )->pack(); my $change_button = $mw->Button( -text => "Toplevel repacked", -command => \&do_Toplevel_repack )->pack(); ######### make a top level withdrawn ################## # make $tl global so it's memory space is reused my $tl = $mw->Toplevel(); $tl->protocol('WM_DELETE_WINDOW' => sub { print "do nothing here\n"; #prevents destruction of $tl #by WM control }); $tl->geometry('300x300+100+100'); $tl->title( "Toplevel" ); $tl->Button( -text => "Close", -command => sub { $tl->withdraw; $spawn_button->configure(-state=>'normal'); $change_button->configure(-state=>'normal'); })->pack(); $tl->withdraw; MainLoop; sub do_Toplevel { $spawn_button->configure(-state=>'disabled'); $change_button->configure(-state=>'disabled'); $tl->deiconify(); $tl->raise(); } sub do_Toplevel_repack { $spawn_button->configure(-state=>'disabled'); $change_button->configure(-state=>'disabled'); #clean out top level my @w = $tl->packSlaves; foreach (@w) { $_->packForget; } $tl->title( "Toplevel repack" ); $tl->geometry('300x500+100+100'); $tl->Button( -text => "Close1", -command => sub { $tl->withdraw; $spawn_button->configure(-state=>'normal'); $change_button->configure(-state=>'normal'); })->pack(); my $text = $tl->Scrolled('Text')->pack(); for (1..100){ $text->insert('end', "$_\n"); $text->see('end'); } #add whatever widgets you want here # Entries, etc $tl->Button( -text => "Add button to mainwindow", -command => sub { $mw->Button(-text=>'new Button')->pack(-side =>'bottom'); })->pack(); $tl->deiconify(); $tl->raise(); }

    I'm not really a human, but I play one on earth Remember How Lucky You Are
Re: perl/tk...how to create interactive widgets inside toplevel window
by Anonymous Monk on Dec 05, 2008 at 12:07 UTC
    Run widget, you'll see tons of examples.
      i didn't get you ... what do you mean by "run widget"??
Re: perl/tk...how to create interactive widgets inside toplevel window
by ig (Vicar) on Dec 05, 2008 at 13:33 UTC

    Following a tutorial introduction to Perl/Tk will help you get your program going. You can try perldoc Tk::UserGuide or Tk Tutorial, Featuring Your Very Own "Perl Sig/OBFU Decoder Ring" or google perl/tk tutorial.

    Start by copying the programs exactly as they are in the tutorial and get something working. Then you can make changes to make them they way you want them. Until you are familiar, it will probably be easiest for you to make one change at a time and then test, being sure to keep a copy of your last working version. If your program stops working after a change, then you know where the problem is and can easily go back to the working version and try again.

    When you have specific problems, read How do I post a question effectively? and post your code with a description of what you expect and what actually happens.

Re: perl/tk...how to create interactive widgets inside toplevel window
by Anonymous Monk on Dec 05, 2008 at 12:16 UTC
    1. ...and interactive widgets

      What are they supposed to do?

    2. i have written the code

      What code?

    3. but its not working

      What is it doing instead?

    4. -container and -use but i dont know how to use them

      What have you tried? See 2.

    5. please help

      We'll try, but it's your turn first.

      hello, actually i am trying to create a birth day reminder tool, i have a main window with six or seven buttons,each button showing a option to the user ,
      1st button create database:- i want when the user press the button a popup will appear with three or four labeled entry options then the user will press enter and internally i will collect those data name ,bday, mobno,emailid and create a hash of hashes i also want that when user press enter the entry fields will be cleaned off for the next entry so that user can enter another set of data and of course there will be a exit button to exit from this window.