shankar.chandra has asked for the wisdom of the Perl Monks concerning the following question:

Hi experts, I am not a full programmer. I kind of do it for my needs. My request could be easy to do with Perl-Tk but I have no clue how to...

I have a notebook with Sheets added inside a foreach loop. Inside each tab I have Text area that displays log using fileevent. Works really well.

The window is launched and $log_display->insert('end', $_ ); works great.

I want to 'add' more tabs to this notebook dynamically from another job start if a condition is met.

Since the widgets are created already, I was looking for a function like 'get all opened mainwindow' and for the new job, I thought I could add the new tab to the handle.

My code skeleton looks like: my $window = Tk::MainWindow->new(); my $book = $window->NoteBook(); #geometry, pack, title etc @input=("corner1","corner2")#generated by another loop #other buttons frames etc foreach my $corner (@input) { $tab = $book->add("TAB $index", -label => "$corner"); $for_display=$tab->Scrolled('Text', )->pack(); #blah blah $CHILD = IO::Handle->new; open($CHILD, "$unix_command 2>&1 |"); $logWindow->fileevent($CHILD, 'readable', [\&callback,args]); } #then using sub callback will insert the $_ if sysread.
I want to update this mainwindow when I start the same pm file. My application request is not allowing me to 'add' using a button or so. I have to detect the previous window and add to it. hope I was clear! :-)

how to achieve this?

Replies are listed 'Best First'.
Re: Perl-Tk Notebook - add a new tab to exisitng $mw
by Anonymous Monk on Sep 10, 2016 at 08:04 UTC
      Hi, thanks for the answer. If I execute ./example.pm (your sample code) for the second time, my $top = MainWindow->new( ); is again executed. Iam not using $top that I created before or? my problem is exactly this. my code will be fully recreated. i will lose my $top. i can save the $top hash to a file but I don't know to recreate the $top reading from the file, if this could be a solution.

        Hi,

        Now I understand what you're talking about

        Yup, once program ends, everything is gone

        When running program again , your program has to recreate everything, every window tab text .... and load all the content into it

        See ->parent and ->children from Tk::Widget , use it to find all the children of a mainwindow, and with a bit of recursion, all their childrens children ...

        Also get Tk::WidgetDump , use it for figuring out Tk