Next: Simple Button using PyEval Prev: Examples Up: Examples Top: Top

5.3.1. Simple Button using AddCallback

This example demonstrates about the simplest possible example of using the Mrm module. There are three files required---a .uil file named button.uil, a .uid file named button.uid, and a Python script named testbutton.py.

button.uil contains the following text:

button.uil is compiled to button.uid by the statement:

testbutton.py (which must have execute permission) contains the following left-justified text:

The script is executed by the statement:

When executed, the testbutton.py script first declares the function OnActivate(). OnActivate is a typical callback function, called with widget, client data and call data arguments. It prints its widget and client data argument. The call data argument is binary, hence ugly when printed.

Then the script declares the function main(). main() opens the hierarchy defined by button.uid, fetches the widget named "main", which is a bulletin board, and its child, a pushbutton. Next, main() uses NameToWidget to obtain a Python widget object for the button widget, and adds OnActivate() as the XmNactivateCallback function, passing "Hi" as the client data. main() then manages these widgets, realizes the shell, and enters the Xt Event Loop.

Finally, the script invokes main(), which executes the function main(), and generates the interface as described above.

When the user pushes the pushbutton (labelled "Push Me" by the XmNlabelString resource specified in the .uil file), the OnActivate() function is called with the string "Hi" as its client data. OnActivate prints "Hi" on stdout.