Prabu Subroto wrote:

> Dear my friends...
>
> Anybody would be so kind telling me what is similar in
> perl/tk to arrange the location of a form written in
> perl/tk? I want a nice look for my perl/tk
> application.
> Somewhat like this below:
> 1. Name      : <place to type-in>
> 2. Address   : <place to type-in>
> 3. Telephone : <place to type-in>

Thanks, prabu,

The simple explanation above helps us undestand what you are trying
to do.  I'm not sure what the code you included has to do with this
though.  There are a number of problems with it--enough that I
would suggest that you take things one step at a time when learning
Tk.  The Tk library is a large and somewhat complicated animal.
Each widget you put on a window makes things just a little more
complicated, and debugging just a little bit harder.

I recommend adding widget one at a time to your Tk interface, and
thoroughly testing the widget as is bfore moving on.

For instance, the Entry widget in the script as posted seemed to
not work, and could have been dangerous.  That is because you used
a different packing manager, the placer, to put it in the same
frame as items that had been packed:
$judul = $mw->Label(-text => "Network Administrator Main Menu",
'center')->place(-y => 30,

-x => 0);


As posted, the text enetered by the user was hidden behind the
large command button.  Changing the place command to a simple pack
made it possible to see the output.  You might not like the visual
effect, but it is more important that your widgets do their job.
You can jigger the fine details of placement once you know that the
interface functions.

>From what I see of your code, there should be no need to worry
about geometry of the main workspace at all.  Your workspace is a
single-document interface.  When you open a file or select a new
document, the text widget that holds the document's contents should
be cleared.  The code looks very close to what it will take.

I would recommend rebuilding this one widget at a time, and making
sure that you understand how each widget is working before you put
the next one on.  Yes, this is a lot of work. [*shrug*]  Goes with
the territory.

Also, some tips on code formatting:

If you use hanging indents, use them well.  This style calls for
the => operators to be aligned vertically within each set of
name-value pairs.  This helps understand what goes together when
review, editing and debugging code.

Also, blank lines should appear only when there is some break in
flow that you wish to signal.  You should *NEVER* have a blank line
in the middle of a statement, especially if the statement is a
function call.  I am including a re-format of your code to give you
an idea of how it might work better.

So where are you in your study of the Tk library?  How much have
you worked with it?  There is a definite and steep learning curve
to Tk, but it does function very well.

#my current perl/tk code:
#!/usr/bin/perl -w
use Tk;
my $mw = MainWindow->new;
$mw->title("[EMAIL PROTECTED] NA - Linux Server Administrating
Tool");

$frmm = $mw -> Frame(-borderwidth => 2,
                          -relief =>'ridge')->pack(
                                      -side => 'top',
                                    -anchor => 'n',
                                    -expand => 1,
                                      -fill => 'x');

$mobject = $frmm -> Menubutton(-text => "Administered Object",
  -menuitems => [['command' => "Samba",
                   -command => \&menusamba],
                ['command' => "Squid",
                   -command => \&menusquid]])->pack(
                                     -side  =>'left',
                                    -anchor => 'nw',
                                    -expand => 0);

$msetting = $frmm -> Menubutton(-text => "Setting")->pack(
                                           -side => 'left',
                                         -anchor => 'nw',
                                         -expand => 0,
                                          -after => $mobject);

$mfile = $frmm -> Menubutton(-text => "File",
                      -tearoff => 0,
                    -menuitems => [["command" => "New Document",
                                  -command => \&new_document],
"-"])->pack(
                              -side => 'left',
                            -anchor => 'nw',
                            -expand => 0,
                             -after => $msetting);

$doc_num = 1;
$doc_list_limit = 9;
$mw -> Button(-text => "New Document",
                          -command => \&new_document)->pack(
                               -side => 'bottom',
                             -anchor => 'e');

$entry = $mw->Entry(-width => 80)->pack(
                        -expand => 1,
                         -fill => 'both');

$mexit = $frmm -> Button(-text => "Exit",
                      -command => \&keluar,
                  -borderwidth => 0)->pack(-side => 'left',
                                 -anchor => 'nw',
                                         -expand => 0,
                                          -after => $mfile);

$mhelp = $frmm -> Menubutton(-text => "Help")->pack(
                                           -side => 'right',
                                         -anchor => 'ne',
                                         -expand => 0);

$judul = $mw->Label(-text => "Network Administrator Main Menu",
                  -anchor => 'center')->pack();

MainLoop;

sub keluar{
        exit();
}

sub menusamba{
        $judul = $mw->Label(-text => "");
}

sub new_document{
        my $name = "Document $doc_num";
        $doc_num++;

        push (@current,$name);
        $filem->command(-label => "$name",
                      -command => [\&select_document, $name ]);
        &select_document($name);
        if ($#current > $doc_list_limit){
                $filem->menu->delete(2);
                shift(@current);
        }
}

sub select_document {
        my ($selected) = @_;
        $entry->delete(0,'end');
        $entry->insert('end',"SELECTED DOCUMENT:$selected");
}


Joseph


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to