Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: greg Newsgroups: comp.lang.tcl Subject: Re: How to do callbacks to methods Date: Thu, 11 Jul 2024 12:17:08 +0200 Organization: A noiseless patient Spider Lines: 62 Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Thu, 11 Jul 2024 12:17:09 +0200 (CEST) Injection-Info: dont-email.me; posting-host="9be51c00966dfec898df4c40cc697fc1"; logging-data="2545031"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Ac+ALPEnFbhiyArQ8EyGnzpW9xdGLggE=" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:a5fWIwN7ozKr5jyzuanbQkz9FKc= Content-Language: de-DE In-Reply-To: Bytes: 2611 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 {my on_quit} > bind {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 [callback on_quit] bind [callback on_quit] } method on_quit {} { destroy . } method show {} { wm deiconify . raise . } } set application [App new] $application show