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

Hello, Here is the code:
1 #! /usr/bin/perl 2 3 use Tk; 4 use Tk::NoteBook; 5 6 $num_adapters = 0; 7 $adapt_tabs = 0; 8 $inter = 0; 9 $inter2 = 0; 10 $count2; 11 $adapt_tabs = 0; 12 $num1; 13 @interface[$num1]; 14 $s1=0; 15 $page_num = 0; 16 17 # Create MainWindow 18 19 $win_main = MainWindow->new(-background => 'black'); 20 $win_main->title ("IP Configuration"); 21 $win_main->geometry("350x150+0+0"); 22 23 #Add Notebook Widget to the main window 24 $nb = $win_main->NoteBook(); 25 26 #Run ipconfig command and put results into the @list array 27 @list = `ipconfig /all`; 28 29 #Walk through the information in the @list array and 30 #make a page for host information 31 foreach (@list) { 32 33 if (/Host/) { 34 ($label,$value) = split /:/; 35 $title = "Host: " . $value; 36 $host_tab = $nb->add("Host", -label => $title); 37 } 38 # Count the number of adapters, parse the name and add the name to +the 39 # @interface array 40 41 if (/Ethernet adapter/) { 42 43 $int_name = $_; 44 $int_name =~ s/Ethernet adapter//; 45 $int_name =~ tr/://d; 46 chop $int_name; chop $int_name; 47 @interface[$num1] = $int_name; 48 $num1++; 49 $num_adapters++; 50 } 51 } 52 53 # Create a page for each interface 54 55 foreach (@interface) { 56 $page_name = $_; 57 #$lname = "a" . $s1; 58 $int[$s1] = $nb->add($s1, -label => $page_name); 59 $s1++ 60 } 61 62 #Print page names 63 64 @pn = $nb->pages; 65 foreach (@pn) { 66 print $_ . "\n"; 67 } 68 69 # Process the information onto the pages 70 71 foreach (@list) { 72 73 ($lab1,$val1) = split /:/; 74 $lab_len = length $lab1; 75 $val_len = length $val1; 76 $output = $label . ": " . $value; 77 78 79 if (/Ethernet adapter/) { 80 $nb->$page_num->Label(-textvariable => $output)->pack(); 81 $page_num++; 82 } 83 else { 84 $nb->$page_num->Label(-textvariable => $output)->pack(); 85 } 86 } 87 88 $win_main->pack(-side => 'left', -anchor => 'nw'); 89 90 91 MainLoop;
The problem I am having is lines 80 and 84. When I run the script I get the following error:
Failed to AUTOLOAD 'Tk::NoteBook::0' at ipc1.pl line 84
So my question is how do I address a "page" in the NoteBook and add things like Labels or text?

Replies are listed 'Best First'.
Re: How do I put Widgets/Information onto TK::NoteBook pages
by kvale (Monsignor) on May 03, 2004 at 00:05 UTC
    The problem is that you are creating page objects in line 58, but are not using them to configure the page. Try something along the lines of (pulled from working code):
    my $n = $globals_main->NoteBook(-ipadx => 6, -ipady => 6); my $basic_p = $n->add("basic", -label => "Basic", -underline => 0); $basic_p->LabEntry(-label => "number of samples to load for inference" +, -labelPack => [-side => "left", -anchor => "w"], -width => 10, -textvariable => \$load_samples )->pack(-side => "top", -anchor => "nw");

    -Mark

      I could use your suggestion if I were not dynamically generating the names. I confirm the names that I generated using lines 64-68. So the application knows that the page Host exists and it knows that pages 0-# of interfaces on my system exist and they are numerically named 0-# of interfaces. So when I request $nb->$page_num, the $page_num translates directly to a named page. So if I am reading all the examples correctly, I can not dynamically allocate pages and put data on them?
        First: use strict! There are questionable lines in your code. You have the @int array containing the page widgets, why not use this one instead of the wrong code in the lines 80 and 84?