Hi again,

Whew - I'm glad BlueBlazerRegular seconded my opinion - I thought I may have been out in left field on this one. I recalled a post I made a while ago (can't find it at the moment) where I produced some code that explored the children of various widgets and tried to recursively set options. This is probably not a good way to set options for widgets but may help you understand how some more complex constructs are created.

Here I have modified your code to recurse the children of the 'File' Menubutton widget. The only child it finds is a Tk::Menu object which it does manage to set the background color for (so the tear-off is purple now as well as the button).

Oddly enough the separator is still not purple unless you tear it off! Bizarre. My next experiment will be to bind that nexted foreach into a callback so that we can see how the children of Tk::Menu change as the menu is in different states.

#!/usr/bin/perl -w use strict; use Tk; my $main = MainWindow->new(); $main->minsize( qw(450 250) ); $main->title("Look! My first Perl/Tk window."); $main->configure(-background => 'Cyan' ); my $menu_bar = $main->Frame(-relief=>'groove', -borderwidth => 3, -background => 'purple', )->pack(-side =>'top', -fill=>'x'); my $file_mb = $menu_bar->Menubutton(-text=>'File', -background=>'purple', -activebackground=>'cyan', -foreground=>'white', )->pack(-side =>'left'); my $file_mb2 = $menu_bar->Menubutton(-text=>'Help', -background=>'purple', -activebackground=>'cyan', -foreground=>'white', )->pack(-side =>'left'); $file_mb->command(-label=>'Exit', -activebackground =>'magenta', -command=>sub{$main->destroy}); $file_mb->separator(); # Code to recurse the children of '$file_mb' # again - don't do this in real life. :) foreach ($file_mb->children) { print "$_\n"; $_->configure(-background => 'purple'); #Interestingly only Tk::Menu is found an it has no children... foreach ($_->children) { print "\t>$_\n"; if ($_->cget('-background')) { $_->configure(-background => 'purple'); } } } MainLoop();
{NULE}
--
http://www.nule.org

In reply to Re: Simple Tk question. by {NULE}
in thread Simple Tk question: colour of drop-down menu by DigitalKitty

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.