Tk Source Code

Artifact [7098ec04]
Login

Artifact 7098ec04e598bf2f035606d35eab986a381aa11796ccc87ea9a5e64b19165b59:

Attachment "menufreezereproduction.tcl" to ticket [33b3af1c] added by bdubzkc 2026-07-21 13:05:02. (unpublished)
#!/usr/bin/env wish

proc openModal {label} {
    set top .modal
    catch {destroy $top}

    toplevel $top
    wm title $top "Modal dialog ($label)"
    wm geometry $top 300x140

    label $top.l -text "Click this button or type below."
    pack $top.l -padx 20 -pady {15 5}

    entry $top.e
    pack $top.e -padx 20 -pady 5 -fill x
    focus $top.e

    button $top.b -text Close -command [list destroy $top]
    pack $top.b -pady 10

    wm transient $top .
    wm protocol $top WM_DELETE_WINDOW [list destroy $top]
    catch {grab set $top}

    tkwait window $top
}

proc direct {} {
    openModal direct
}

proc deferred {} {
    after idle {openModal deferred}
}

wm title . "Tk macOS menu-callback deadlock repro"

label .info -justify left -text \
    "Use the Test menu.\n\nDirect opens synchronously.\nDeferred opens after idle."
pack .info -padx 20 -pady 20 -fill both -expand 1

menu .menubar
. configure -menu .menubar

menu .menubar.test -tearoff 0
.menubar.test add command -label "Direct (hangs)" -command direct
.menubar.test add command -label "Deferred (works)" -command deferred
.menubar add cascade -label Test -menu .menubar.test