Re: [R] help: how to use tkevent.generate(...)

From: Peter Dalgaard <p.dalgaard_at_biostat.ku.dk>
Date: Tue 12 Jul 2005 - 21:41:02 EST

wu sz <r.shengzhe@gmail.com> writes:

> Hello,
>
> I use package "tcltk" to do some GUI programming, and want to find a
> function which can do the operation "click a button", just like using
> a mouse to click. If tkevent.generate can do that? I tried it as
> below, but failed. Please give me a hint!
>
> tt <- tktoplevel()
> tkwm.title(tt,"Simple Dialog")
>
> onOK <- function(){print("OK")}
> onCancel <- function(){print("Cancel")}
> OK.but <- tkbutton(tt, text=" OK ", command=onOK)
> Cancel.but <- tkbutton(tt, text="Cancel",command=onCancel)
> tkgrid(OK.but,Cancel.but)
>
> tkevent.generate(tt, onOK)

That would never work: At the very least you need to send *events* and to the right widget, not the toplevel. If you just wanted to run onOK, there's an easier way: onOK(), or generically:

  tcl("eval", tkcget(OK.but, command=NULL))

to run the command associated with OK.but (whether it is an R callback or not).

The right way to trigger a button press event turns out to be a bit tricky, but Googling about (for the tcl/tk counterpart "event generate") found the solution: You need not one, but three events: Entering the button, pressing the mouse button, releasing the mouse button, i.e.:

tkevent.generate(OK.but,"<Enter>")
tkevent.generate(OK.but,"<1>")
tkevent.generate(OK.but,"<ButtonRelease-1>")


for (e in c("<Enter>","<1>","<ButtonRelease-1>"))

   tkevent.generate(OK.but,e)

-- 
   O__  ---- Peter Dalgaard             ุster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk)                  FAX: (+45) 35327907

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Tue Jul 12 21:44:50 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:33:32 EST