Tk Source Code

View Ticket
Login
Ticket UUID: ea459e12c26d6a2f4edd5a1159e62ec2e4fdfee5
Title: scale: -command is called again if the scale is redrawn while the command runs
Type: Bug Version: 9.1 (also 9.0 and 8.6)
Submitter: serhiy.storchaka Created on: 2026-10-20 07:16:02
Subsystem: 15. [scale] Assigned To: aku
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2026-11-03 18:09:12
Resolution: Fixed Closed By: nemethi
    Closed on: 2026-11-03 18:09:12
Description:

If the scale is redrawn while its -command is still running (the command enters the event loop with tkwait, vwait or update), the command is called again with the same value:

set count 0
pack [scale .s -command {apply {v {
    if {[incr ::count] == 1} {
        toplevel .d
        update
        grab .d
        .s configure -troughcolor red
        after 100 {destroy .d}
        tkwait window .d
    }
}}}]
update
.s set 10
after 500 {puts $count}

This prints 2 instead of 1. TkpDisplayScale() (unix/tkUnixScale.c, used on all platforms) clears REDRAW_PENDING before calling the command, but clears INVOKE_COMMAND only after the command returns, so a redraw requested during the command calls it again.

This is probably why scale-23.1 fails on macOS ([99bb36df86]): there, mapping the modal dialog redraws the scale, and the command is called a second time.

User Comments: nemethi (claiming to be Csaba Nemethi) added on 2026-11-03 18:09:12:

Merged by Jan into main, core-9-0-branch, and core-8-6-branch by commits [bc3442af], [82740804], and [94a16d81]. Closing the ticket.


serhiy.storchaka added on 2026-10-20 07:16:58:

Proposed fix in branch scale-command-redraw: INVOKE_COMMAND is cleared before calling the command. Value changes made by the command itself still do not call it again, as before. New test scale-23.2.