79324322

Date: 2025-01-02 16:14:15
Score: 2
Natty:
Report link

I have come up with a partial solution.

First, the tcl/tk code I'm trying to emulate

proc callback1 { data } { puts "callback1 $data" }
proc callback2 { data } { puts "callback2 $data" }
bind all <<EVENT>>  "+callback1 %d"
bind all <<EVENT>>  "+callback2 %d"
toplevel .wtop -width 100 -height 100

event generate .wtop <<EVENT>> -data ZZZZZ
event generate .wtop <<EVENT>> -data 1234567

Here is the partial solution R code

library(tcltk)

callback1 = function(d) { cat('callback1',d,'\n') ; invisible() }
invisible(.Tcl(paste('proc callback1 { } { ', .Tcl.callback(callback1),'}')))
invisible(.Tcl('bind all <<EVENT>> +callback1'))

callback2 = function(d) { cat('callback2',d,'\n') ; invisible() }
invisible(.Tcl(paste('proc callback2 { } { ', .Tcl.callback(callback2),'}')))
invisible(.Tcl('bind all <<EVENT>> +callback2'))

w.top = tktoplevel()

invisible(tkevent.generate(w.top,'<<EVENT>>',data='ZZZZZ'))
invisible(tkevent.generate(w.top,'<<EVENT>>',data='1234567'))

However the output from both of the generated events is just

callback1 %d 
callback2 %d

I have tried putting "%d" in various places in the .Tcl() calls but they all give errors. Can anyone complete this answer?

Reasons:
  • Long answer (-1):
  • Has code block (-0.5):
  • Ends in question mark (2):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: re2 re2