in reply to How to change colour of a Tkx button when pressed

I FIGURED IT OUT!!!!! The following is the line of code on the second line of the -command line. You just have to change the letter to match the button.

Tkx::i::call(".b", "configure", "-background", "blue");

Replies are listed 'Best First'.
Re^2: How to change colour of a Tkx button when pressed
by james28909 (Deacon) on Jun 25, 2016 at 01:55 UTC
    You could have also killed the button on press, and then made a new one in its place... the color you wanted.
Re^2: How to change colour of a Tkx button when pressed
by Anonymous Monk on Oct 05, 2016 at 08:26 UTC

    This is most curious since all the docs I have read says Tkx buttons don't have any color attributes. NTL, I tried for some time to make your code work with the "eureka I found it pseudo-code" and failed. Would you have time to reply again with an exact replacement for the bad code in the OP? As in, ...broke code line... ... working code line... Would be greatly appreciated. BTW: I am using W7/64, /w perl 5, version 24, subversion 0 (v5.24.0) built for MSWin32-x64-multi-thread ..blah.. Binary build 2400 300558 provided by ActiveState ...Built Jun 9 2016 21:44:59 it that helps. Much thanks.

      This is most curious since all the docs I have read says Tkx buttons don't have any color attributes.

      background is http://www.tcl.tk/man/tcl8.4/TkCmd/options.htm#M-background

      NTL, I tried for some time to make your code work with the "eureka I found it pseudo-code" and failed.

      floor slippery?

        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();