grail.widgets.gokcancelbuttons module

Version: 16.2

Table of Contents

Description

The GOkCancelButtons widget provides a script writer with the ability to quickly insert the standard OK and cancel button idiom into their dialogs.

Example

The following example posts a window with an OK and cancel button on it. When the user clicks the OK button, the script will print out "OK" and close. Likewise, when the user clicks the cancel button, the script will print out "cancel" and close. Normally you would do your dialog validation on when the OK button is closed, and then go ahead and process your instructions.

from grail.widgets import *
from Tkinter import *

def on_ok():
print "OK"
root.destroy()

def on_cancel():
print "CANCEL"
root.destroy()

root = gwidgetinit()
root.title("GOkCancelButton Example")
root.geometry("%dx%d" % (250, 100))

okcancel = GOkCancelButtons(root,
okbutton_command=on_ok,
cancelbutton_command=on_cancel)
okcancel.pack(anchor='sw', side='right')
root.mainloop()

The above script will create a window that appears as follows,

Screen shot of the GOkCancelButtons widget.

Example of the GOkCancelButtons widget.

GOkCancelButtons Widget

The GOkCancelButtons widget inherits from,
class GOkCancelButtons([parent, **keywords])

Defines a standard ok and cancel dialog button set.

Arguments:
parent : Tkinter.Frame
Parent widget, widget we insert into.
keywords
Variable keyword list defined below.
Keywords:
All keywords are prefixed with the sub-components name. For example, to access the text for the OK button, you would use the okbutton_text keyword. Two useful keywords are the okbutton_command and cancelbutton_command that are executed when the user clicks the OK and cancel buttons respectively.
Components:
okbutton
The OK button.
cancelbutton
The cancel button.
Signals:
const.sigON_OK
When the user clicks the OK button.
const.sigON_CANCEL
When the user clicks the cancel button.