in reply to Re^3: How to change colour of a Tkx button when pressed
in thread How to change colour of a Tkx button when pressed

My bad, I was using: Tkx::ttk__button()
whereas your code used: Tkx::button()
Sigh. BTW: I am writing my very 1st Tkinter code, so your help is greatly appreciated.

The latter surely supports "-background".
However, I still cannot get the color to change.
So, I reduced your example to 2 buttons, code at bottom.

One confusion is "what replaces the 'i' in: Tkx::i:..."
as noted in your "I FIGURED IT OUT" response:

  Tkx::i::call(".b", "configure", "-background", "blue");
Your response says:
  "You just have to change the letter [I presume ::i::] to match the button."
The other confusion: where is the syntax to spec what gets "call"'ed...
  "Undefined subroutine &Tkx::button::call...:
Complete runtime error is below.

For ref, the following 2-command example works fine:
  -command => sub { print "18L\n"; print "18L #2\n"; },
So I tried the following (yep, some desperation flailing...):
  -command => sub { print "18L\n"; Tkx::.b::call(".b", "configure", "-background", "blue"); },
  -command => sub { print "18L\n"; Tkx::button::call(".b", "configure", "-background", "blue"); },
  -command => sub { print "18L\n"; Tkx::".b"::call(".b", "configure", "-background", "blue"); },
#3 = syntax error (obviously)
#1 and #2 = the following runtime (Application) error, after clicking the "18-Letters" button:

Undefined subroutine &Tkx::button::call called at H:\NotPhotos\Computer\Raspberry_Pi\Perl\test2.pl line 15.
Undefined subroutine &Tkx::button::call called at H:\NotPhotos\Computer\Raspberry_Pi\Perl\test2.pl line 15.
    while executing
"::perl::CODE(0x4de7f0)"
    invoked from within
".b invoke"
    ("uplevel" body line 1)
    invoked from within
"uplevel #0 list $w invoke"
    (procedure "tk::ButtonUp" line 24)
    invoked from within
"tk::ButtonUp .b"
    (command bound to event)

use strict; use warnings; use Tkx; my $mw = Tkx::widget->new("."); $mw->g_wm_title("Jobs Not Forecasted"); Tkx::button(".b", -text => "18-Letters", -background => "red", -width => 11, -command => sub { print "18L\n"; print "18L #2\n"; }, # OK # -command => sub { print "18L\n"; Tkx::.b::call(".b", "configure", " +-background", "blue"); }, # BAD, runtime error # -command => sub { print "18L\n"; Tkx::button::call(".b", "configure +", "-background", "blue"); },# BAD, runtime error # -command => sub { print "18L\n"; Tkx::".b"::call(".b", "configure", + "-background", "blue"); }, # BAD, syntax error ); Tkx::pack(".b"); Tkx::button(".s", -text => "EXIT", -width => 11, -command => sub { Tkx::destroy("."); }, ); Tkx::pack(".s"); Tkx::MainLoop();

Replies are listed 'Best First'.
Re^5: How to change colour of a Tkx button when pressed
by Anonymous Monk on Oct 05, 2016 at 22:32 UTC

    I posted #4 and after some more experimenting got things to work. Just needed to c/p cowboy's code literally. In my defense, his comment
    "You just have to change the letter to match the button."
    mislead me... who would have thought there was a Tkx::i::... method (the "letter i") and most real code wouldn't have used ".b" as the widget id. What a waste of time. FTR, the following snipped works as reported.

    ...snip... my $mw = Tkx::widget->new("."); $mw->g_wm_title("Jobs Not Forecasted"); Tkx::button(".b", -text => "18-Letters", -background => "red", -width => 11, -command => sub { print "18L\n"; Tkx::i::call( ".b", "configure", +"-background", "blue" ); } }, ); Tkx::pack(".b"); ...snip...
Re^5: How to change colour of a Tkx button when pressed
by Anonymous Monk on Oct 05, 2016 at 23:19 UTC