G'day Marshall,

You asked me two questions about your code (via /msg). Generally, I'd recommend you actually post these questions; that way, if I'm unavailable, someone else could answer them. I'll answer the second question first: it applies to the answer to the first question.

"With the geometry statement, I couldn't get the listbox to appear at top of the main frame"

That has nothing to do with geometry(). If you manually resize the GUI, you'll see the Listbox in the centre of the left-hand side. Look for -side and -anchor in Tk::pack. The former defaults to top, you've changed it to left, that's where it appears, all good so far. The latter defaults to center, you haven't changed that, so it appears in the centre, not what you want; had you changed that to n, it would appear at the top (which is where you want it).

"Maybe you can show me how to make my code work as OP intended"

Here's a brief list of changes I made to your code:

Here's the modified code:

#!/usr/bin/env perl use strict; use warnings; use Tk; my $mw = MainWindow->new; $mw->geometry('400x250'); my $FirstFrame = $mw->Frame( -bg => 'lavender', -relief => 'sunken', )->pack(-expand => 1, -fill => 'both'); my $listbox = $FirstFrame->Scrolled('Listbox', -bg => 'white', -scrollbars => "e", -selectmode => 'extended', -width => 200/7, -height => 212/15, )->pack(qw{-side left -anchor n -padx 50 -pady 12}); my @strings2 = qw/apples bananas pears grapes/ x 5; $listbox->insert('end',@strings2); MainLoop();

This code now renders exactly the same as the OP's original code.

There is only one difference in functionality that I detected. If you manually resize the GUI, with this code, the Listbox will also resize; with the OP's code, the Listbox will be chopped off on the right, at the bottom, or possibly on both of those sides. In either case, I can still scroll the list with the mousewheel. So that's a serendipitous improvement.

— Ken


In reply to Re^4: TK Placing Widgets in a Scrolling Pane by kcott
in thread TK Placing Widgets in a Scrolling Pane by saiftynet

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.