avo has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks, I have being developing a Perl/Tk application under Windows for a while. After a while I've decided to run it on my Linux (openSuse 10.2). Everything was looking right, except the background color of all frames and windows. I am doing something very simple in Windows: $mw->setPalette(background=>'black'); This results in a default black background of all windows. In Linux this doesn't work. I remember that time ago I had similar problem, which I simply solved by running X without window manager, where I could start the application normal - with setPalette working. I tried to find an option in the window manager that maybe overrides the palettes ... but with no luck. Please help me. Regards
  • Comment on TK setPalette Not working under Linux Gnome

Replies are listed 'Best First'.
Re: TK setPalette Not working under Linux Gnome
by zentara (Cardinal) on Jun 24, 2007 at 12:53 UTC
    Well this works for me on linux. I use ICEWM and the latest Xserver version. May say what Tk, distribution, Perl, and Xserver versions you have going.

    Ugly.... but demonstrates it works.

    #!/usr/bin/perl use warnings; use strict; use Tk; my $types = [['Format Perl', '.pl']]; my $mw = new MainWindow ( ) ; $mw->setPalette(background=>'black', foreground=>'white'); my @files; $mw -> Button ( -text => 'Select File ' , -command => \&open_it )-> pack(-padx=>5, -pady=>5) ; MainLoop ( ) ; sub open_it { my $names = $mw ->getOpenFile ( -initialdir => '.', -filetypes => $types, -multiple => 1) ; foreach my $file( @{$names} ){ print "Result ", $file, "\n" ; } }

    I'm not really a human, but I play one on earth. Cogito ergo sum a bum
      Yeah, it works, but only under FVWM or plain X. I guess ICEWM falls under these. I tried it under KDE and Gnome... doesn't work. I think the window manager somehow overrides the palette colors. I am not sure, and very confused. In fact I don't know what I must do next. My application is quite large, and I don't feel like changing all Frames, top levels, etc. to have an option for background and foreground ... I know that you can recursively change all children's background for instance. But not all my windows are loaded... I load them dynamically. My application works fine in FVWM. I would appreciate any input. Thanks Zentara.
Re: TK setPalette Not working under Linux Gnome
by zentara (Cardinal) on Jun 25, 2007 at 12:13 UTC
    You might be better off using optionAdd, instead of setPallette, but you may need to set the optionAdd for all toplevel windows. This works, but looks a bit different (better in my opinion)
    #!/usr/bin/perl use warnings; use strict; use Tk; my $types = [['Format Perl', '.pl']]; my $mw = new MainWindow ( ) ; $mw->optionAdd('*foreground' => 'white'); $mw->optionAdd('*background' => 'black'); #$mw->setPalette(background=>'black',foreground=>'white'); my @files; $mw -> Button ( -text => 'Select File ' , -command => \&open_it )-> pack(-padx=>5, -pady=>5) ; MainLoop ( ) ; sub open_it { my $names = $mw ->getOpenFile ( -initialdir => '.', -filetypes => $types, -multiple => 1) ; foreach my $file( @{$names} ){ print "Result ", $file, "\n" ; } }

    I'm not really a human, but I play one on earth. Cogito ergo sum a bum
      Hi Zentara, You are right. This works like a bomb! I am very happy! Thanks a lot for the solution. Your help is highly appreciated! I will list you in my About section :) The software I am developing has a small site here: http://www.wtspace.com/spacepos/
        The POS system looks very professional.

        I'm not really a human, but I play one on earth. Cogito ergo sum a bum
      Just last question. I noticed that the elements such as Canvas and Scale has got a white border around it. Button, Label funny enough doesn't have it. Let me know if you need a screenshot, please. I think it is just another option, but I can't figure out the name. I tried all border related ones... but no luck. Thanks for your great help!
        The optionAdd mechanism isn't fully foolproof. You may have to manually add the options to each widget. Each widget will act a bit differently. You might also want to ask on comp.lang.perl.tk, where someone else may know a useful trick or two. As you can see below, the highlightthickness only works on a per widget basis.

        It may be a bit late now, but Gtk2 has better uniformity of control over all widget parameters, in Tk, each widget has a distinct personality.

        #!/usr/bin/perl use warnings; use strict; use Tk; my $mw = tkinit; $mw->optionAdd('*foreground' => 'yellow'); $mw->optionAdd('*background' => 'black'); $mw->optionAdd('*borderwidth' => 0); $mw->optionAdd('*insertborderwidth' => 0); $mw->optionAdd('*selectborderwidth' => 0); $mw->optionAdd('*highlightthickness' => 0); $mw->optionAdd('*hightlightcolor' => 'black'); $mw->optionAdd('*selectbackground' => 'black'); my $f = $mw->Frame(-borderwidth => 0, -highlightthickness => 0, )->pack(-expand => 1, -fill => 'both', ); $f->Label(-text => 'First label')->pack; $f->Text( -highlightthickness => 0 )->pack; my $canvas = $f->Scrolled("Canvas", -highlightthickness => 0 )->pack(); MainLoop;

        I'm not really a human, but I play one on earth. Cogito ergo sum a bum