上部にメニューバーフレーム、I / O用に左右に2つのフレーム、入力フレームでPerl Tkモジュールを使用してGUIアプリケーションを作成したいのですが、いくつかのオプションを下部に並べて配置したいと思います。
フレームの下部に複数のボタン/チェックボックスを一列に並べたいのですが。-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.")
}
別のフレーム(-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);
それはどのように見えるか:
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加