Button constructors

Share:

Description

A button widget is used to present a widget that a user can press to initiate some action.

Buttons show text and/or images in a clickable object whose shading indicates that the button is to clicked on.

Usage

1
2
gbutton(text = "", border=TRUE, handler = NULL, action = NULL, container = NULL, 
    ..., toolkit = guiToolkit()) 

Arguments

text

Text to show in the button. For buttons, if this text matches a stock icon name, an icon is shown as well.

border

If TRUE a border is drawn to make a button look like a button. If FALSE, the no border so the button looks like a label.

handler

Handler called on a click event

action

Either a gaction instance in which case, the text and handler arguments are not used, or is an R object to be passed to the specified handler.

container

Optional container to attach widget to.

...

Passed to add method of container

toolkit

Which GUI toolkit to use

Details

As buttons are intended to show the user how to initiate some action, they are often labeled as commands. Additionally, if the action is not currently possible given the state of the GUI, a button is typically disabled. This can be done through the enabled method.

The svalue() method returns the value of the widget. For a button, this is the text as a single string (which may not include a "\n" for newlines if not supported by the toolkit).

The svalue<- method can be used to set the text of the widget. For buttons, values with length greater than one are pasted together collapsed with "\n".

The addHandlerChanged method is aliased to the addHandlerClicked method which can be used to set a handler to respond to click events.

When the action argument is a gaction instance, then the button label and handler will be derived from the gaction instance. The enabled<- method of the gaction instance should be used to set the sensitivity to user input, not the enabled<- method of the gbutton instance.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
## Not run: 
  ## button group example
  w <- gwindow("Button examples")
  g <- ggroup(container = w)
  addSpring(g)   ## push to right of widget
  gbutton("help", container = g)
  addSpace(g, 20) ## some breathing room
  gbutton("cancel", container = g)
  gbutton("ok", container = g, handler = function(h, ...) cat("do it\n"))

## End(Not run)

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.