1

Perl Tk モジュールを使用して GUI アプリケーションを作成し、メニューバー フレームを上部に、左右に 2 つのフレームを i/o 用に、入力フレームに、いくつかのオプションを下部に並べて表示したいと考えています。

フレームの下部に複数のボタン/チェックボックスを一列に並べたいと思います。-anchor=>'n' などのオプションを試しましたが、どれも機能していないようです。

私の現在のコードは、「ここをクリック」を「完了」の上に置きますが、それらを一列に並べたいと思っています。どのように行うべきですか (パック ジオメトリ マネージャーを使用)?

#!/usr/bin/perl
use strict;
use warnings;
use Tk;

my $mw = MainWindow->new;
$mw->geometry("1000x500");
$mw->title("Text Formatter");

#-----------------Frames-----------------------#
my $main_frame = $mw->Frame()->pack( -side => 'top', - fill => 'x' );
my $top_frame =
  $mw->Frame( -background => 'purple' )->pack( -side => 'top', -fill => 'x' );
my $left_frame =
  $mw->Frame( -background => 'white' )->pack( -side => 'left', -fill => 'y' );
my $right_frame =
  $mw->Frame( -background => 'white' )->pack( -side => 'right', -fill => 'y' );

#----------------Widgets-------------------------#
$top_frame->Label(
    -text => "Simple Text Formatter", 
    -background => 'cyan' 
    ) ->pack( -side => 'top' );

$left_frame->Label(
    -text       => "Enter the text here that you wish to format",
    -background => 'yellow'
    )->pack( -side => 'top', -fill => 'both' );

$right_frame->Label( 
    -text => "Formatted Text", 
    -background => 'yellow' 
    )->pack( -side => 'top', -fill => 'both' );

my $left_text;

my $exitButton= 
    $left_frame->Button(
    -text => "Done", 
    -command => sub { exit } 
    )->pack( -side => 'bottom',-fill=>'both',-expand=>1);

my $executeButton =
    $left_frame->Button(
    -text    => "Click here",
    -command => sub { Echo($left_text); }
    )->pack( -side => 'bottom',-fill=>'both',-expand=>1);


$left_text =
  $left_frame->Text(
    -height => 29.4, 
    -width => 71 
    )->pack( -side => 'left', -fill => 'both',-expand=>1 );

my $right_output = $right_frame->Text(
    -background => 'black',
    foreground  => 'white',
    -height     => 40,
    -width      => 71
    )->pack( -side => 'left',-fill=>'both',-expand=>1 );

MainLoop;

sub Echo {
    my ($widget) = @_;
    my $text = $widget->Contents();
    $right_output -> delete('1.0','end');
    my ($size,$maxlength,$lines)=(0,0,0);
    my @data=split /\n/,$text;
    foreach my $line(@data)
    {
        $lines++;
    $size+=length($line);
    $line=~s/\r|\n//g;
    my $len=length($line);
    $maxlength = $maxlength >= $len ? $maxlength:$len;
    $right_output->insert('end',"->$line<-\n")
    }
    $right_output->insert("end","\n$lines lines,longest line has $maxlength characters,$size bytes total.")
}
4

1 に答える 1

3

別のフレーム (-side => 'bottom') を使い、そこにボタン (-side => 'left') を詰め込みます。

my $left_text;

my $buttons =
    $left_frame->Frame()->pack(-side => 'bottom', -fill=>'both', -expand=>1);

my $exitButton=
    $buttons->Button(
    -text => "Done",
    -command => sub { exit }
    )->pack(-side => "left", -fill => "both", -expand => 1);

my $executeButton =
    $buttons->Button(
    -text    => "Click here",
    -command => sub { Echo($left_text); }
    )->pack(-side => "left", -fill => "both", -expand => 1);

どのように見えるか:

どのように見えるか

于 2014-04-13T20:15:49.997 に答える