in reply to perl/tk show script progress

I added zentara's script to mine and got this:
#!/usr/bin/perl use strict; use warnings; use Tk; use Tk::NoteBook; my $starttime; my $raisetime; my $progressbar; my $percent_done; my $mw = MainWindow->new(); $mw->geometry("400x100"); my $book = $mw->NoteBook()->pack( -fill => 'both', -expand => 1 ); my $tab1 = $book->add( "Sheet 1", -label => "Start", -createcmd => \&getStartTi +me ); my $tab2 = $book->add( "Sheet 2", -label => "Continue", -raisecmd => \&getCurre +ntTime ); my $tab3 = $book->add( "Sheet 3", -label => "Progress", -createcmd => \&getProg +ressBar ); my $tab4 = $book->add( "Sheet 4", -label => "Command", -createcmd => \&getExecu +teCommand ); my $tab5 = $book->add( "Sheet 5", -label => "End", -state => 'disabled +' ); $tab1->Label( -textvariable => \$starttime )->pack( -expand => 1 ); $tab2->Label( -textvariable => \$raisetime )->pack( -expand => 1 ); $tab3->Button( -text => 'Quit', -command => sub { exit; } ) ->pack( -expand => 1 ); MainLoop; sub getStartTime { $starttime = "Started at " . localtime; } sub getCurrentTime { $raisetime = " Last raised at " . localtime; $book->pageconfigure( "Sheet 3", -state => 'normal' ); } sub getProgressBar { my $mw = MainWindow->new( -title => 'ProgressBar example' ); my $progress = $mw->ProgressBar( -width => 30, -from => 0, -to => 100, -blocks => 50, -colors => [ 0, 'green', 50, 'yellow', 80, 'red' ], -variable => \$percent_done )->pack( -fill => 'x' ); $mw->Button( -text => 'Go!', -command => sub { for ( my $i = 0 ; $i < 1000 ; $i++ ) { $percent_done = $i / 10; print "$i\n"; $mw->update; } } )->pack( -side => 'bottom' ); MainLoop; } sub getExecuteCommand { use Tk; use Tk::ExecuteCommand; use Tk::widgets qw/LabEntry/; use strict; my $mw = MainWindow->new; my $ec = $mw->ExecuteCommand( -command => '', -entryWidth => 50, -height => 10, -label => '', -text => 'Execute', )->pack; $ec->configure(-command => 'date; sleep 10; date'); my $button = $mw->Button(-text =>'Do_it', -background =>'hotpink', -command => sub{ $ec->execute_command }, )->pack; MainLoop; }

Replies are listed 'Best First'.
Re^2: perl/tk show script progress
by swoop (Acolyte) on Sep 08, 2011 at 19:32 UTC
    Much appreciated!! Looks better, but I will still need to work on this to make my second perl script to execute and run in a GUI window. I'd really like to get my second perl script to run within the same window as the main GUI, such as, one of the tabs. Essentially one large GUI window at the top some buttons and at the bottom an inset window where my second perl script would run.

      Hi,

      Not sure why you need a second script, could you not use a sub kicked off by a button?

      I think you want to print text messages 'log style', you could use a scrolled-textbox for this. Check for it in the Tk manual.

      J.C.

      Or perhaps a listbox, non-selectable, might do the trick.

      J.C.

        Thank you JC I will look into this tomorrow. I have developed a tool with perl to migrate routers running IOS to XR. Now I want to incorporate the migration tool into a GUI. I'm having a difficult time deciding if I should use perl/tk or some other language to do so.