• Flash label background

    From snosniv@21:1/5 to All on Thu Mar 16 05:50:04 2023
    I want to draw attention to the user when they change power mode.
    So I've tried the following using the 'after' command, but not working.

    label $f9.lb00 -text "Watts" -font {Arial 10 bold} -width 14 -bg lightblue1 -fg $Watt_Colgrid
    $f9.lb00 -row 0 -column 0



    proc togglePwr {} {
    global POWsel f9
    if {$POWsel == 1} {
    # Power label
    $f9.lb00 configure -text "Watts" -bg lightblue1 -fg $Watt_Col
    after 500 $f9.lb00 configure -bg grey
    after 500 $f9.lb00 configure -bg lightblue1
    } else {
    $f9.lb00 configure -text "FTP" -bg green-fg $FTP_Col
    after 500 $f9.lb00 configure -bg grey
    after 500 $f9.lb00 configure -bg green
    }
    }

    So, ignoring the 'after' commands, the label changes text & colour just fine, but I'd like to flash the background just a few times somehow?
    The added after is not doing anything I can see.
    The aim was to add a small loop of 'after' cmds to flash the bg 4 or 5 times,
    I don't want it flashing permanently, just a few to get users attention.

    TIA, Kev P.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ralf Fassel@21:1/5 to All on Thu Mar 16 16:17:57 2023
    * snosniv <[email protected]>
    | proc togglePwr {} {
    | global POWsel f9
    | if {$POWsel == 1} {
    | # Power label
    | $f9.lb00 configure -text "Watts" -bg lightblue1 -fg $Watt_Col
    | after 500 $f9.lb00 configure -bg grey
    | after 500 $f9.lb00 configure -bg lightblue1
    | } else {
    | $f9.lb00 configure -text "FTP" -bg green-fg $FTP_Col
    | after 500 $f9.lb00 configure -bg grey
    | after 500 $f9.lb00 configure -bg green
    | }
    | }

    | So, ignoring the 'after' commands, the label changes text & colour just fine, | but I'd like to flash the background just a few times somehow?
    | The added after is not doing anything I can see.

    It *is* doing something, but since you set up *two* after commands for
    the same interval, they run immediately after each other, the second
    undoing the effect of the first.

    Either use
    after 500 [list $f9.lb00 configure -bg grey]
    after 1000 [list $f9.lb00 configure -bg lightblue1]
    (note: different intervals) or set up a proc which gets a count as
    argument, decrs the count and calls itself via [after] while the
    count is > 0

    proc do_n_times {n interval} {
    # do something
    puts "do_n_times $n $interval [clock milliseconds]"
    incr n -1
    if {$n > 0} {
    after $interval [list do_n_times $n $interval]
    }
    }

    do_n_times 5 500
    =>
    do_n_times 5 500 1678979708511
    do_n_times 4 500 1678979709011
    do_n_times 3 500 1678979709511
    do_n_times 2 500 1678979710011
    do_n_times 1 500 1678979710512

    You may want to add arguments for the widgets to change etc.

    HTH
    R'

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From snosniv@21:1/5 to Ralf Fassel on Thu Mar 16 08:57:12 2023
    On Thursday, 16 March 2023 at 15:18:03 UTC, Ralf Fassel wrote:
    * snosniv <[email protected]>
    | proc togglePwr {} {
    | global POWsel f9
    | if {$POWsel == 1} {
    | # Power label
    | $f9.lb00 configure -text "Watts" -bg lightblue1 -fg $Watt_Col
    | after 500 $f9.lb00 configure -bg grey
    | after 500 $f9.lb00 configure -bg lightblue1
    | } else {
    | $f9.lb00 configure -text "FTP" -bg green-fg $FTP_Col
    | after 500 $f9.lb00 configure -bg grey
    | after 500 $f9.lb00 configure -bg green
    | }
    | }

    | So, ignoring the 'after' commands, the label changes text & colour just fine,
    | but I'd like to flash the background just a few times somehow?
    | The added after is not doing anything I can see.
    It *is* doing something, but since you set up *two* after commands for
    the same interval, they run immediately after each other, the second
    undoing the effect of the first.

    Either use
    after 500 [list $f9.lb00 configure -bg grey]
    after 1000 [list $f9.lb00 configure -bg lightblue1]
    (note: different intervals) or set up a proc which gets a count as
    argument, decrs the count and calls itself via [after] while the
    count is > 0

    proc do_n_times {n interval} {
    # do something
    puts "do_n_times $n $interval [clock milliseconds]"
    incr n -1
    if {$n > 0} {
    after $interval [list do_n_times $n $interval]
    }
    }

    do_n_times 5 500

    do_n_times 5 500 1678979708511
    do_n_times 4 500 1678979709011
    do_n_times 3 500 1678979709511
    do_n_times 2 500 1678979710011
    do_n_times 1 500 1678979710512

    You may want to add arguments for the widgets to change etc.

    HTH
    R'

    Thanks Ralf, I misunderstood the 'after', thinking they were sequential.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)