Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Simple Tk question: colour of drop-down menu

by DigitalKitty (Parson)
on May 01, 2002 at 02:22 UTC ( #163203=perlquestion: print w/ replies, xml ) Need Help??
DigitalKitty has asked for the wisdom of the Perl Monks concerning the following question:

Hi all.

Is a drop down menu supposed to be grey? I am teaching myself Perl/Tk programming and when I clicked on the title bar, I noticed that the menu item is 'greyed out'. Shouldn't the -background define the whole area?

#!/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(); MainLoop();

Thanks,
-Caitlin

Edit kudra, 2002-05-03 Added info after : in title

Comment on Simple Tk question: colour of drop-down menu
Download Code
Re: Simple Tk question.
by {NULE} (Hermit) on May 01, 2002 at 17:17 UTC
    Hi DigitalKitty,

    Background does change the background of the menu drop-downs, but you have to use it to configure the buttons you wish to change.

    $file_mb->command(-label=>'Exit', -background => 'purple', -activebackground =>'magenta', -command=>sub{$main->destroy});
    This doesn't change either the tear-off widget or the separator widget, and I have not ever had luck getting these to look the way I like.

    Maybe one of the other monks can provide a better answer for you - I'd be interested to know as well. I probably need to spend some quality time with Tk/Menubutton.pm to see what is actually happening, this is something I'd like to be able to customize as well.

    Good luck,
    {NULE}
    --
    http://www.nule.org

    P.S. For just learning Perl/Tk this code looks good - keep it up!

Re: Simple Tk question.
by BlueBlazerRegular (Friar) on May 01, 2002 at 17:48 UTC

    I will second {NULE} - for just starting out, this code looks good. Especially the use of warnings and strict. And to top it off, I found a solution to one of my problems by reviewing your code.

    As {NULE} mentions, you need to apply the background to each menu item. The issue with the tear-off and the separator bar are actually two different things. The tear-off item can be fixed by using the 'setPalette' option on the main window, like this:

    $main->setPalette('cyan');

    This does more than just set the color - it supposedly changes the entire color palette so border shadowing and other such things appear correctly, although I haven't seen much impact on other widgets.

    The separator bar issue is actually under the windowing system's (i.e., Windows, KDE, Gnome) control. If, for example, you go change the underlying display control (in Windows go to the 'Appearance' tab in the 'Display Properties' group - accessed via a right-click on the desktop) this will affect the window's borders along with the separator bar. Like {NULE}, I haven't found a way to override that behavior.


    Good luck. And if you do solve the separator bar problem, please share it with us.


    Pat
Re: Simple Tk question.
by {NULE} (Hermit) on May 01, 2002 at 18:00 UTC
    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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://163203]
Approved by mattriff
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (8)
As of 2014-10-25 14:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (143 votes), past polls