Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

wxPerl button background

by xircon (Initiate)
on Dec 17, 2014 at 19:25 UTC ( [id://1110660]=perlquestion: print w/replies, xml ) Need Help??

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

In my search for enlightenment, I have stumbled....
$button2->SetForegroundColour(Wx::Colour->new(177,77,77));
Works.... Button text is red, but:
$button2->SetBackgroundColour(Wx::Colour->new(177,77,77));
(or whatever colour). Does nothing.

Replies are listed 'Best First'.
Re: wxPerl button background
by jmlynesjr (Deacon) on Dec 17, 2014 at 22:15 UTC

    From the wxWidgets docs for wxWindow::SetBackgroundColour:

    Remarks: The background colour is usually painted by the default wxEraseEvent event handler function under Windows and automatically under GTK. Note that setting the background colour does not cause an immediate refresh, so you may wish to call wxWindow::ClearBackground or wxWindow::Refresh after calling this function. Using this function will disable attempts to use themes for this window, if the system supports them. Use with care since usually the themes represent the appearance chosen by the user to be used for all applications on the system.

    James

    There's never enough time to do it right, but always enough time to do it over...

Re: wxPerl button background
by GotToBTru (Prior) on Dec 17, 2014 at 19:52 UTC

    What module(s) are you using? I can guess what SetForegroundColour is supposed to do, but without any context, I have no idea if you have a simple spelling error, or are missing some environmental setting, or ...

    1 Peter 4:10
      Very new to perl. Manjaro linux, wx installed via cpanm. Very simple script
      #!/usr/bin/perl -w use strict; use Wx; my $backcolor = Wx::Colour->new('#123582'); my $butbackcol = Wx::Colour->new('#198cff'); ## Button margin my $l=5; ## Centre screen workaround #my $cw=1366/2; #my $ch=500/2; package MyFrame; use base 'Wx::Frame'; # import the event registration function use Wx::Event qw(EVT_BUTTON); sub new { my $ref = shift; my $self = $ref->SUPER::new( undef, # parent window -1, # ID -1 means any 'Variety Control', # title [50, 50], # default position [100, 150], # size ); my $panel = Wx::Panel->new( $self, # parent window -1, # ID ); $panel->SetBackgroundColour($backcolor); my $button1 = Wx::Button->new( $panel, # parent window -1, # ID 'Next >>', # label [$l, 10], # position [-1, -1], # default size ); # register the OnClick method as an handler for the # 'button clicked' event. The first argument is a Wx::EvtHandler # that receives the event # $button1->SetBackgroundColour($butbackcol); EVT_BUTTON( $self, $button1, \&OnClick1 ); my $button2 = Wx::Button->new( $panel, # parent window -1, # ID '<<Previous', # label [$l, 50], # position [-1, -1], # default size ); ## Here is where I am having problems : $button2->SetForegroundColour(Wx::Colour->new(177,77,77)); + $button2->SetBackgroundColour(Wx::Colour->new(177,77,77)); #$button2->SetBackgroundColour(Wx::Colour->new('red')); # register the OnClick method as an handler for the # 'button clicked' event. The first argument is a Wx::EvtHandler # that receives the event EVT_BUTTON( $self, $button2, \&OnClick2 ); my $button3 = Wx::Button->new( $panel, # parent window -1, # ID 'Trash', # label [$l, 90], # position [-1, -1], # default size ); # register the OnClick method as an handler for the # 'button clicked' event. The first argument is a Wx::EvtHandler # that receives the event EVT_BUTTON( $self, $button3, \&OnClick3 ); return $self; } # this method receives as its first parameter the first argument # passed to the EVT_BUTTON function. The second parameter # always is a Wx::Event subclass sub OnClick1 { my( $self, $event ) = @_; #$self->SetTitle( 'Clicked' ); system("variety","-n"); } sub OnClick2 { my( $self, $event ) = @_; #$self->SetTitle( 'Clicked' ); system("variety","-p"); } sub OnClick3 { my( $self, $event ) = @_; #$self->SetTitle( 'Clicked' ); system("variety","-t"); } package MyApp; use base 'Wx::App'; sub OnInit { my $frame = MyFrame->new; $frame->Centre("wxBoth"); $frame->Show( 1 ); } package main; my $app = MyApp->new; $app->MainLoop;
      To control variety wallpaper changer, playing with a simple example to expand my knowledge. wxperl
      yaourt wx | grep -i installed 2 extra/wxgtk 3.0.2-2 [installed] 3 extra/wxgtk2.8 2.8.12.1-2 [installed] 11 community/wxsqlite3 3.1.1-1 [installed] 43 aur/perl-alien-wxwidgets 0.65-1 [installed] (43) 45 aur/perl-wx 0.9923-1 [installed] (35) 47 aur/perl-wx-perl-processstream 0.32-1 [installed] (8) 48 aur/perl-wx-scintilla 0.40_02-2 [installed] (5) 86 aur/wxformbuilder-bin 3.1.70-2 [installed] (3)
      Is the best I can do. Steve

        I'm unable to test this directly (at work atm). I did note one thing in my quick search of the documentation: the paragraph on SetBackgroundColour warns that the method itself does not produce a visible change, the screen must be refreshed first.

        1 Peter 4:10

        I'd expect that if it does set the background red, the 3d Button effect ends up covering that red color.

        Perhaps try a BitmapButton instead?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (8)
As of 2024-04-18 08:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found