inst/examples/GtkImage-2.R

# Handling button-press events on a GtkImage
button_press_callback <- function(event_box, event, data) {
  print(paste("Event box clicked at coordinates ", event[["x"]], ",",
              event[["y"]], sep=""))

  ## Returning TRUE means we handled the event, so the signal 
  ## emission should be stopped (don't call any further 
  ## callbacks that may be connected). Return FALSE
  ## to continue invoking callbacks.
  
  return(TRUE)
}

create_image <- function() {
  image <- gtkImage(file="myfile.png")
  
  event_box <- gtkEventBox()
  event_box$add(image)
  
  
  gSignalConnect(event_box, "button_press_event", button_press_callback, image)
  
  return(image)
}

Try the RGtk2 package in your browser

Any scripts or data that you put into this service are public.

RGtk2 documentation built on Oct. 14, 2021, 5:08 p.m.