#!/usr/bin/perl # https://perlmonks.org/?node_id=1226501 use warnings; use strict; use Tk; use List::Util qw( max ); require Tk::Pane; my $mw = MainWindow->new(); $mw->geometry("1400x900+0+40"); my $headFrame = $mw->Scrolled('Pane', -scrollbars => 'se', -height=>60, -width=>1300, -bg=>'orange')->grid( -row => 0, -column => 0); my $dataFrame = $mw->Scrolled('Pane', -scrollbars => 'se', -height=>700, -width=>1300, -bg=>'gray')->grid( -row => 4, -column => 0); my $horiz = $dataFrame->Subwidget('xscrollbar'); $horiz->configure(-command => sub { $headFrame->xview(@_); $dataFrame->xview(@_) }); #open my $dataFH, "<", $ARGV[0] or die "Could not open $ARGV[0]"; my $row = 0; my $hRow = 0; #while(!eof $dataFH) while( ) { #my $data=readline($dataFH); chomp; my $data = $_; my @dataArr = split '\|', $data; my $column = 0; my $bg='gray'; if($dataArr[0] =~ m/^Record/) { $bg='orange'; foreach my $field (@dataArr) { my $label = $headFrame->Label(-height=>2, -bg=>$bg, -fg=>'black', -text => $field, -relief => 'ridge'); $label->grid( -sticky=> 'ew', -row => $hRow, -column => $column++); } $hRow++; } else { foreach my $field (@dataArr) { my $label = $dataFrame->Label(-height=>2, -bg=>$bg, -fg=>'black', -text => $field, -relief => 'ridge'); $label->grid( -sticky=> 'ew', -row => $row, -column => $column++); } $row += 1; } } $mw->idletasks; my ($columns, $rows) = $dataFrame->Subwidget('pane')->gridSize(); for my $cnt ( 0 .. $columns - 1 ) { my ($arg1, $arg2, $width, $arg4) = $dataFrame->Subwidget('pane')->gridBbox($cnt, 0); my( $arg1a, $arg2a, $hWidth, $arg4a) = $headFrame->Subwidget('pane')->gridBbox($cnt, 0); my $maxwidth = 6 + max($hWidth, $width); $headFrame->Subwidget('pane')->gridColumnconfigure($cnt, -minsize=>$maxwidth); $dataFrame->Subwidget('pane')->gridColumnconfigure($cnt, -minsize=>$maxwidth); } $mw->MainLoop; __DATA__ Record|one|two|three|one|two|three|one|two|three|one|two|three|one|two|three|one|two|three|one|two|three|one|two|three|one|two|three|one|two|three|one|two|three|one|two|three|one|two|three|one|two|three|one|two|three|one|two|three|one|two|three|one|two|three dataforrecord|one|two|three|one|two|three|one|two|three|one|two|three|one|two|three|one|two|three|one|two|three|one|two|three|one|two|three|one|two|three|one|two|three|one|two|three|one|two|three|one|two|three|one|two|three|one|two|three|one|two|three|one|two|three