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

Hi, I am writing a script that searches for a file and reports about it, but i am having problems designing the user interface. I am using Tk and the pack function for this. Here is the code i have so far:

use strict; use warnings; use Tk; my $mw = new MainWindow; $mw->geometry("400x400"); my $text = $mw->Text(-width=>15,-height=>3)->pack(-side=>'bottom',-anc +hor=>'w',-padx=>20,-pady=>10); my $label = $mw->Label(-text=>"File?",-anchor=>'w')->pack(-side=>'left +',-anchor=>'n',-padx=>20,-pady,10); my $entry = $mw->Entry->pack(-side=>'left',-anchor=>'n',-padx=>20,-pad +y=>10); my $button = $mw->Button(-text => "search!",-width=>30)->pack(-side => + 'left',-anchor=>'n',-padx=>20,-pady=>10); MainLoop;

As you can see the textarea is located all the way to the bottom while i want it just below the other widgets. So all i need is to loose some vertical space but i am unable to do this. Sorry for my poor engish, please advice.

Replies are listed 'Best First'.
Re: Tk design user interface
by Tux (Abbot) on Jan 23, 2020 at 12:59 UTC

    Something like this? (use a Frame):

    use strict; use warnings; use Tk; my $mw = new MainWindow; $mw->geometry ("400x400"); my $tf = $mw->Frame->pack ( -side => "top", -expand => 0, -fill => "x", ); my $label = $tf->Label ( -text => "File?", -anchor => "w", )->pack ( -side => "left", -anchor => "w", -padx => 20, -pady => 10, ); my $entry = $tf->Entry->pack ( -side => "left", -anchor => "w", -padx => 20, -pady => 10, ); my $button = $tf->Button ( -text => "search!", -width => 30, )->pack ( -side => "right", -anchor => "e", -padx => 20, -pady => 10, ); my $text = $mw->Text ( -width => 15, -height => 3, )->pack ( -side => "top", -anchor => "nw", -padx => 20, -pady => 10, -expand => 1, -fill => "both", ); MainLoop;

    Enjoy, Have FUN! H.Merijn

      Thank you!

Re: Tk design user interface
by tybalt89 (Parson) on Jan 23, 2020 at 13:58 UTC

    Either

    #!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11111771 use warnings; use Tk; my $mw = new MainWindow; #$mw->geometry("400x400"); my $text = $mw->Text(-width=>15,-height=>3 )->pack(-side=>'bottom',-anchor=>'w',-padx=>20,-pady=>10); my $label = $mw->Label(-text=>"File?",-anchor=>'w' )->pack(-side=>'left',-anchor=>'n',-padx=>20,-pady,10); my $entry = $mw->Entry ->pack(-side=>'left',-anchor=>'n',-padx=>20,-pady=>10); my $button = $mw->Button(-text => "search!",-width=>30 )->pack(-side => 'left',-anchor=>'n',-padx=>20,-pady=>10); MainLoop;

    Or

    #!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11111771 use warnings; use Tk; my $mw = new MainWindow; $mw->geometry("400x400"); my $frame = $mw->Frame->pack; my $label = $frame->Label(-text=>"File?",-anchor=>'w' )->pack(-side=>'left',-anchor=>'n',-padx=>20,-pady,10); my $entry = $frame->Entry ->pack(-side=>'left',-anchor=>'n',-padx=>20,-pady=>10); my $button = $frame->Button(-text => "search!",-width=>30 )->pack(-side => 'left',-anchor=>'n',-padx=>20,-pady=>10); my $text = $mw->Text(-width=>15,-height=>3 )->pack(-side=>'top',-anchor=>'w',-padx=>20,-pady=>10); MainLoop;

      yes, ty