I am failing to get a hide/show dialog to show more than once

Liste des GroupesRevenir à cl tcl 
Sujet : I am failing to get a hide/show dialog to show more than once
De : mark (at) *nospam* qtrac.eu (Mark Summerfield)
Groupes : comp.lang.tcl
Date : 26. Jun 2024, 10:59:48
Autres entêtes
Message-ID : <eYecndBfv-AJe-b7nZ2dnZfqnPUAAAAA@brightview.co.uk>
User-Agent : Pan/0.154 (Izium; 517acf4)
I've made a cut-down example shown below.
If I click the Options button the Options dialog shows as it should.
And if I click the Options dialog's Close button it is hidden.
But if I click the Options button a second time I get the error:

bad window path name ".optionsForm"

Clearly I've made a mistake, but I don't know Tcl/Tk well enough to see
what I've done wrong.

#!/usr/bin/env wish9

package require tepam

tk scaling 1.67
tk appname HideShow

proc main {} {
    wm withdraw .
    wm title . [tk appname]
    wm attributes . -type dialog
    wm minsize . 200 200
    make_widgets
    wm deiconify .
    raise .
}

namespace eval test {
    variable optionsButton
    variable optionsForm
}

proc make_widgets {} {
    set test::optionsButton [ttk::button .optionsButton -text Options… \
        -underline 0 -command test::on_options]
    pack .optionsButton
    bind . <Alt-o> {$test::::optionsButton invoke}
    bind . <Escape> {destroy .}
}

# Hide/show dialog
proc test::on_options {} {
    if {![info exists ::test::optionsForm]} {
        puts "on_options init"
        set ::test::optionsForm [toplevel .optionsForm]
        wm title .optionsForm "Options — [tk appname]"
        ttk::label .optionsForm.label -text "Options go here"
        grid .optionsForm.label -row 0 -column 0
        ttk::button .optionsForm.closeButton -text Close \
            -command {destroy $::test::optionsForm}
        grid .optionsForm.closeButton -row 1 -column 0
        dialog prepare .optionsForm
        wm protocol .optionsForm WM_DELETE_WINDOW \
            {dialog hide $::test::optionsForm}
        bind .optionsForm <Escape> {destroy $::test::optionsForm}
    }
    puts on_options
    dialog show .optionsForm
}

namespace eval dialog {}

tepam::procedure {dialog prepare} {
    -named_arguments_first 0
    -args {
        {-modeless -type none}
        {-parent -default .}
        {window}
    }
} {
    wm withdraw $window
    wm attributes $window -type dialog
    if {!$modeless} { wm transient $window $parent }
}

tepam::procedure {dialog show} {
    -named_arguments_first 0
    -args {
        {-modeless -type none}
        {-focuswidget -default ""}
        {window}
    }
} {
    puts "dialog show $window"
    wm deiconify $window
    raise $window
    focus $window
    if {$focuswidget ne ""} {focus $focuswidget}
    if {!$modeless} {
        catch {grab set $window}
        catch {tkwait visibility $window}
    }
}

tepam::procedure {dialog hide} {
    -args { {window} }
} {
    wm withdraw $window
    grab release $window
}

main

Date Sujet#  Auteur
26 Jun 24 * I am failing to get a hide/show dialog to show more than once5Mark Summerfield
26 Jun 24 `* Re: I am failing to get a hide/show dialog to show more than once4Ralf Fassel
27 Jun 24  +- Re: I am failing to get a hide/show dialog to show more than once1Mark Summerfield
27 Jun 24  `* Re: I am failing to get a hide/show dialog to show more than once2Mark Summerfield
27 Jun 24   `- Re: I am failing to get a hide/show dialog to show more than once1Ralf Fassel

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal