========================================= ``grail.widgets.gokcancelbuttons`` module ========================================= .. include:: ../../version.h .. include:: ref.h .. contents:: Table of Contents :backlinks: top ----------- Description ----------- The :c:`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. .. Python:: 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, .. figure:: figure-gokcancelbuttons-example.gif :alt: Screen shot of the GOkCancelButtons widget. Example of the :c:`GOkCancelButtons` widget. ----------------------- GOkCancelButtons Widget ----------------------- The :c:`GOkCancelButtons` widget inherits from, * :c:`gwidget.GWidget` (grail.widgets.gwidget_) * :c:`objsignal.Emitter` (grail.objsignal_) class :dc:`GOkCancelButtons([parent, **keywords])` Defines a standard ok and cancel dialog button set. Arguments: :a:`parent` : :c:`Tkinter.Frame` Parent widget, widget we insert into. :a:`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 :a:`okbutton_text` keyword. Two useful keywords are the :a:`okbutton_command` and :a:`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: :d:`const.sigON_OK` When the user clicks the OK button. :d:`const.sigON_CANCEL` When the user clicks the cancel button.