我想使用 Perl Tk 模块制作一个 GUI 应用程序,顶部有一个菜单栏框架,左右两个框架用于 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.")
}