• Re: How to do callbacks to methods

    From Mark Summerfield@21:1/5 to All on Thu Jul 11 08:04:56 2024
    Sorry for the noise, I found the solution on the wiki:

    #!/usr/bin/env wish9
    proc ::oo::Helpers::callback {method args} {
    list [uplevel 1 {namespace which my}] $method {*}$args
    }
    tk appname "Test App"
    oo::class create App {
    constructor {} {
    wm withdraw .
    wm title . [tk appname]
    grid [ttk::button .quitButton -text Quit -underline 0 \
    -command [callback on_quit]]
    bind . <Escape> [callback on_quit]
    bind . <Alt-q> [callback on_quit]
    }
    method on_quit {} {
    destroy .
    }
    method show {} {
    wm deiconify .
    raise .
    }
    }
    set application [App new]
    $application show

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mark Summerfield@21:1/5 to All on Thu Jul 11 07:44:29 2024
    In the app below none of the callbacks works, neither in the bind calls
    nor the -command. I am using Tcl/Tk 9.0b2 on Linux. How can I make these callbacks work?

    #!/usr/bin/env wish9
    tk appname "Test App"
    oo::class create App {
    constructor {} {
    wm withdraw .
    wm title . [tk appname]
    grid [ttk::button .quitButton -text Quit -underline 0 \
    -command {my on_quit}]
    bind <Escape> {my on_quit}
    bind <Alt-q> {my on_quit}
    }
    method on_quit {} {
    destroy .
    }
    method show {} {
    wm deiconify .
    raise .
    }
    }
    set application [App new]
    $application show

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From greg@21:1/5 to All on Thu Jul 11 12:17:08 2024
    Am 11.07.24 um 09:44 schrieb Mark Summerfield:
    In the app below none of the callbacks works, neither in the bind calls
    nor the -command. I am using Tcl/Tk 9.0b2 on Linux. How can I make these callbacks work?

    #!/usr/bin/env wish9
    tk appname "Test App"
    oo::class create App {
    constructor {} {
    wm withdraw .
    wm title . [tk appname]
    grid [ttk::button .quitButton -text Quit -underline 0 \
    -command {my on_quit}]
    bind <Escape> {my on_quit}
    bind <Alt-q> {my on_quit}
    }
    method on_quit {} {
    destroy .
    }
    method show {} {
    wm deiconify .
    raise .
    }
    }
    set application [App new]
    $application show

    Hello,
    solution: callback
    https://www.tcl.tk/man/tcl9.0/TclCmd/callback.html



    package require Tk

    # helpers proc for 8.6
    #proc ::oo::Helpers::callback {method args} {
    # list [uplevel 1 {namespace which my}] $method {*}$args
    #}

    #https://www.tcl.tk/man/tcl9.0/TclCmd/callback.html

    tk appname "Test App"
    oo::class create App {
    constructor {} {
    wm withdraw .
    wm title . [tk appname]
    grid [ttk::button .quitButton -text Quit -underline 0 \
    -command [callback on_quit]]
    bind <Escape> [callback on_quit]
    bind <Alt-q> [callback on_quit]
    }
    method on_quit {} {
    destroy .
    }
    method show {} {
    wm deiconify .
    raise .
    }
    }
    set application [App new]
    $application show

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mark Summerfield@21:1/5 to All on Fri Jul 12 07:14:25 2024
    Thank you!

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