Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Limitations with Tkx configure options?

by murrayn (Sexton)
on Sep 10, 2012 at 07:58 UTC ( #992699=perlquestion: print w/replies, xml ) Need Help??
murrayn has asked for the wisdom of the Perl Monks concerning the following question:

I wrote a gui using Tk and changed button colours successfully. I upgraded my ActiveState perl and found that Tk no longer builds correctly so I changed to Tkx. Now I can't configure a button's background colour despite finding various examples showing me that I should do as follows:
use Tkx; my $mw = Tkx::widget->new("."); my $calc = $mw->new_ttk__button(-text=>"Calculate", -command=>sub {cal +culate();}); $calc->g_grid(-column=>1,-row=>3,-columnspan=>2,-sticky=>"ew"); $calc->g_bind("<Enter>", sub {$calc->configure(-background=>'red');}); Tkx::MainLoop();
I get the following error which is fairly self-explanatory except that I understood, from what doc (mainly Tk, NOT Tkx) that it should work.
unknown option "-background" at /TestCode/ line 5. unknown option "-background" while executing ".b configure -background red" invoked from within "::perl::CODE(0x4af0d4)" (command bound to event)
Am I attempting the impossible or do I need some other module to discover these attributes?

Replies are listed 'Best First'.
Re: Limitations with Tkx configure options?
by Anonymous Monk on Sep 10, 2012 at 09:10 UTC

    Here are the available configure options

    #!/usr/bin/perl -- use strict; use warnings; use Data::Dump qw/ pp /; $Tkx::TRACE = 64; use Tkx; my $mw = Tkx::widget->new("."); my $calc = $mw->new_ttk__button( -text => "Calculate", -command => \&calculate +); $calc->g_grid( -column => 1, -row => 3, -columnspan => 2, -sticky => " +ew" ); sub calculate { pp [ $calc->configure ]; $calc->configure( -background => 'red' ); } Tkx::MainLoop(); __END__ $ perl winfo children . ttk::button .b -text Calculate -command + perl::callback grid .b -column 1 -row 3 -columnspan 2 + -sticky ew .b configure [ bless([ bless([ "-takefocus", "takeFocus", "TakeFocus", "ttk::takefocus", "ttk::takefocus", ], "Tcl::List"), bless(["-command", "command", "Command", "", "::perl::CODE(0xa84ec +c)"], "Tcl::List"), bless(["-default", "default", "Default", "normal", "normal"], "Tcl +::List"), bless(["-text", "text", "Text", "", "Calculate"], "Tcl::List"), bless(["-textvariable", "textVariable", "Variable", "", ""], "Tcl: +:List"), bless(["-underline", "underline", "Underline", -1, -1], "Tcl::List +"), bless(["-width", "width", "Width", "", ""], "Tcl::List"), bless(["-image", "image", "Image", "", ""], "Tcl::List"), bless(["-compound", "compound", "Compound", "none", "none"], "Tcl: +:List"), bless(["-padding", "padding", "Pad", "", ""], "Tcl::List"), bless(["-state", "state", "State", "normal", "normal"], "Tcl::List +"), bless(["-takefocus", "takeFocus", "TakeFocus", "", "ttk::takefocus +"], "Tcl::List"), bless(["-cursor", "cursor", "Cursor", "", ""], "Tcl::List"), bless(["-style", "style", "Style", "", ""], "Tcl::List"), bless(["-class", "", "", "", ""], "Tcl::List"), ], "Tcl::List"), ] .b configure -background red
Re: Limitations with Tkx configure options?
by Anonymous Monk on Sep 10, 2012 at 09:00 UTC
Re: Limitations with Tkx configure options?
by zentara (Archbishop) on Sep 10, 2012 at 10:24 UTC
    This is just a guess from my Tk experience, but some widgets use -bg instead of -background.

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh
        Thank you. I would seem to be constrained by the settings of the style sheet associated with the widget (and I'm not so desperate for specific colours that I'm going to go revising the style sheet just for fun - there's a job to be done behind all this :) ).
        Those links were very helpful and led to an interesting discovery which appears to differ between ttk and Tk:
        A widget state of active != !disabled. At least not when the Tbutton style applies. I wanted to disable and enable a button during various processes but setting the button's state to "active" did not re-enable it.
        $w->state('!disabled') reverses the effect of $w->state('disabled')
        $w->state('active disabled') is not an oxymoron but it makes the button rather difficult to press while both states exist.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://992699]
Approved by Corion
vrk takes a cookie from the platter on the sideboard.

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2017-04-24 10:24 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (438 votes). Check out past polls.