Am a decent way into programming my first Perl/Tk application. Since the beginning one thing has plagued me ... when I resize the MainWindow all child widgets are centred in the parent. I want them all anchored north. I've returned to this problem many times and still no solution. I've got to be missing something obvious.

Below is the code. The MainWindow contains several frames configured using "grid". A large portion of the code I've snipped out because its not relevant and too long. I also have purposely snipped out Grid row 1 for this example, that's not an error. Run this and see how you go. Thanks for your help.

Dean
#!perl use strict; use warnings; ## Import Perl modules use Tk; use Tk::Widget; use Tk::Date; use Tk::Menubutton; ## Display all shift types and create Radiobuttons for each my $shiftsframe; my $hlistbox; ########################### ## Global variables my ($endtime, $starttime); # start and end times of chosen shift ########################### ## Make Main Window my $mw = MainWindow->new (-title => 'opzTul'); $mw->resizable('false','true'); ########################### ## Make Main menu my $mainMenu = $mw -> Menu ( -type => 'menubar', -tearoff => 0); $mw->configure (-menu => $mainMenu); ########################### ## Make Admin Menu my $adminMenu = $mainMenu -> cascade ( -label => '~Admin', -tearoff => 0); my $reportsMenu = $mainMenu -> cascade (-label => '~Reports', -tearoff => 0); my $helpmenu = $mainMenu -> cascade ( -label => '~Help', -tearoff => 0); my $topframe = $mw -> Frame(-border => 1, -relief => 'sunken'); my $displaydate; my $date = $topframe->Date( -allarrows => 1, -choices => ['yesterday','today','tomorrow'], -value => 'now', -variable => \$displaydate, -fields => 'date', -selectlabel => 'Select', #-varfmt => 'datehash', ); my $shiftselect; my $All = $topframe->Radiobutton(-text => 'All day', -variable => \$shiftselect, -value => 'All' ); ########################### ## Make seperare frame for go button my $goframe = $mw->Frame; my $go = $goframe -> Button(-text => 'Go!', -width => 27, -command => [\&godate, \$displaydate, \$shiftselect] ); ########################### ## Make Middle Frames my $freshframe = $mw->Frame (-border => 1, -relief => 'sunken'); my $freshButton = $freshframe->Button (-text => 'Refresh', -width => 27, -command => [sub {$shiftsframe->DESTROY; &displayshifts; $hlistbox->DESTROY if (Exists($hlistbox)); &showhourlies; }] ); my $h1frame = $mw->Frame (-border => 1, -relief => 'sunken'); my $h2frame = $mw->Frame (-border => 1, -relief => 'sunken'); my $h3frame = $mw->Frame (-border => 1, -relief => 'sunken'); my $quitframe = $mw->Frame (-border => 1, -relief => 'sunken'); my $quitButton = $quitframe->Button ( -text => 'Quit', -width => 27, -command => \&quit); ########################### ## Make bindings to keys $mw -> bind ('<Control-q>', \&quit); ########################### ## Pack and build all elements of the window $topframe -> grid (-row => 2, -columnspan => 4, -sticky => 'n', -pady => 5, -padx => 5,); $date->pack; $All->pack; $goframe->grid (-row => 3, -columnspan => 4, -sticky => 'n', -pady => 5, -padx => 5, ); $All->select; $go->pack; $freshframe -> grid (-row => 4, -columnspan => 4, -sticky => 'n', -padx => 2, -pady => 2); $h1frame -> grid (-row => 5, -column => 3, -sticky => 'n', -padx => 2, -pady => 2); $h2frame -> grid (-row => 5, -column => 3, -sticky => 'n', -padx => 2, -pady => 2); $h3frame -> grid (-row => 5, -column => 3, -sticky => 'n', -padx => 2, -pady => 2); $quitframe -> grid (-row => 6, -columnspan => 4, -sticky => 'n', -padx => 2, -pady => 2); $freshButton->pack; $quitButton->pack; MainLoop; sub quit { print "Quitting ..\n"; $mw -> destroy; }

Edited by Chady -- added readmore tags.


In reply to Perl/Tk - MainWindow positioning all widgets as centred by crabbdean

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.