gibsonca has asked for the wisdom of the Perl Monks concerning the following question:
I'm having trouble with positioning my tk text/input boxes. I'd like them to be either top, left justified, or bottom left justified. I have tried -side <options> The example source shows, among other things, I don't know how to do this. Thanks.
#!/usr/bin/perl use strict; use warnings; use Env; use integer; use File::Find; use feature ":5.10"; use Data::Dumper; use Tk; use Tk::ProgressBar; use Tk::BrowseEntry; use Text::CSV_XS; use Net::FTP; my( $cm21_info_frame, $exit, $g_rfs_Version, $gCm21Dir, $gDir, $gDirectory, $gLoad, $gPcDir, $gOutDir, $gProject, $gUserFile, $help, $mbar, $mw, $pc_info_frame, $txt, ); # MAIN $g_rfs_Version = "debugging"; $gDir = "\\tmp\\abc"; # Main Window $mw = new MainWindow; $mw->geometry("900x400"); $mw->title("MENU DEBUG V +ersion $g_rfs_Version"); &selectProject($mw); &selectLoad($mw); my $main_menu = $mw->Menu(); $mw->configure(-menu => $main_menu); # see if there is a persistence directory to use. $mbar = $mw -> Menu(); $mw -> configure(-menu => $mbar); # The Main Buttons my $file = $mbar -> cascade(-label => "Commands", -underl +ine => 0, -tearoff => 0); my $compile = $mbar -> cascade(-label => "Compile", -underl +ine => 0, -tearoff => 0); my $generate = $mbar -> cascade(-label => "Save Results", -underl +ine => 0, -tearoff => 0); $exit = $mbar -> cascade(-label => "Exit", -underl +ine => 0, -tearoff => 0); $help = $mbar -> cascade(-label => "Help", -underl +ine => 0, -tearoff => 0); ## File Menu ## $file -> checkbutton(-label =>"Select Program", -underline => 0, -command => [\&selectProgram, "Select program"]); $file -> checkbutton(-label =>"Select Directory", -underline => 0, -command => [\&selectDirectory, "Select Directory"]); $file -> checkbutton(-label =>"Select Function", -underline => 0, -command => [\&selectFunction, "Select Function"]); $file -> separator(); # ------------------------------------------ $file -> command(-label =>"Exit", -underline => 1, -command => sub + { exit } ); ### TEXT AREA $txt = $mw -> Scrolled('Text',-width => 130,-scrollbars=>'e') -> pac +k (); $txt->insert('end',"\n Working directory is $gDir"); # CREATE VIEW FRAME my $info_frame = $mw->Frame( -relief => 'ridge', -borderwidth => '1' )->pack(-side => 'bottom', -fill => 'x'); # PC DIRECTORY FRAME $pc_info_frame = $mw->Frame->pack( -side => "bottom", -fill => 'x'); + # Label $pc_info_frame->Label( -text => "PC Directory : " )->pack( -side => "left" ); # Input field $pc_info_frame->Entry( -width => 120, -textvariable => \$gPcDir )->pack( -side => "left" ); ## Compile ## $compile -> command(-label =>"compile test files", -command => sub + { compile(); } ); ## Save Results ## $generate -> command(-label =>"to SUM file", -command => sub { go( +); } ); ## Exit ## $exit -> command(-label =>"out of here", -command => sub { exit(0) +; } ); ## Help ## $help -> command(-label =>"About", -command => sub { $txt->delete('1.0','end'); $txt->insert('end', "About rfs.pl --------------------------------------- Version $g_rfs_Version --------------------------------------- Purpose: 'Commay Author: Website : http://www E-Mail : \n"); }); MainLoop; # ------------------------------------------------- sub selectProject { # pick a project # ------------------------------------------------- my $mother = shift; # Create dropdown and another element which shows my selection my $dropdown_value = "aaa"; my $dropdown = $mother->BrowseEntry( -label => "Project:", -variable => \$dropdown_value, )->pack(-side => "left"); my $showlabel = $mother->Label( -text => "Project: $dropdown_value", )->pack(-side => "left"); # Configure dropdown $dropdown->configure( # What to do when an entry is selected -browsecmd => sub { $showlabel->configure(-text => "Project: $dropdown_value" +), }, ); # Populate dropdown with values foreach ( qw/aaa bbb ccc/ ) { $dropdown->insert('end', $_); } # Set the initial value for the dropdown $dropdown_value = "bbb"; } # end of selectProject() # ------------------------------------------------- sub selectLoad { # pick a load # ------------------------------------------------- my $mother = shift; # Create dropdown and another element which shows my selection my $dropdown_value = "2.1"; my $dropdown = $mother->BrowseEntry( -label => "Load:", -variable => \$dropdown_value, )->pack(-side => "left"); my $showlabel = $mother->Label( -text => "Load: $dropdown_value", )->pack(-side => "left"); # Configure dropdown $dropdown->configure( # What to do when an entry is selected -browsecmd => sub { $showlabel->configure(-text => "Load: $dropdown_value" ), }, ); # Populate dropdown with values foreach ( qw/1.0 1.1 2.0 2.1/ ) { $dropdown->insert('end', $_); } # Set the initial value for the dropdown $dropdown_value = "2.1"; } # end of selectLoad() # ----------------- sub selectDirectory { # ----------------- $gDir = $mw->chooseDirectory; $gDir =~ s/\//\\/g; $gOutDir = $gDir . "\\Converted"; $txt->insert('end',"\n\nNew directory is $gDir"); $gDirectory = $gDir; opendir(DIR, $gDirectory) or die "couldn't open $gDirectory: $!\ +n"; my @files = grep(/\.*$/, readdir(DIR)); closedir DIR; if ($#files < 3) { $txt->insert('end',"\n\n*** ERROR 1 *** \n"); $txt->insert('end',"Directory, $gDirectory, is empty! \n\n"); $mw->update; } } # end of selectDirectory() # ----------------- sub selectProgram { # ----------------- $txt->insert('end',"\n\nSelect Program is TBD"); $mw->update; } # end of selectProgram() # ----------------- sub selectFunction { # ----------------- $txt->insert('end',"\n\nSelect Function is TBD"); $mw->update; } # end of selectFunction() # ----------------- sub compile { # ----------------- $txt->insert('end',"\n\nCompiling function is TBD"); $mw->update; } # end of compile() # --------- sub go { # --------- &OnGenerate(); } # end of go() # of main() ###
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: tk positioning of widgets
by zentara (Archbishop) on Oct 23, 2012 at 10:27 UTC | |
by gibsonca (Beadle) on Oct 23, 2012 at 16:15 UTC | |
by zentara (Archbishop) on Oct 23, 2012 at 18:26 UTC | |
by Anonymous Monk on Oct 24, 2012 at 09:22 UTC | |
Re: tk positioning of widgets
by kcott (Archbishop) on Oct 23, 2012 at 05:31 UTC | |
Re: tk positioning of widgets
by Anonymous Monk on Oct 23, 2012 at 01:26 UTC |
Back to
Seekers of Perl Wisdom