Applet Programming in Ten Easy Steps

The following pages comprise a short guided tour of basic Tk capabilities, demonstrated as Grail applets. Each module follows the same pattern.

First the module's __doc__ string:

Import the Tk widget classes (Tkinter is designed carefully not to export anything undocumented):
    from Tkinter import *
Define a class "App" (any other name would be okay too):
    class App:
The constructor is always the same:
      def __init__(self, parent):
	self.parent = parent
The method to create the widgets is called by the constructor:
      def create_widgets(self):
More methods may follow (e.g. callbacks):
      ...additional methods...
At the very end of the file is some boilerplate code that will create a root window and instantiate the applet class, in case it is run as a stand-alone script instead of a Grail applet:
    # Boilerplate from here on...
    if __name__ == '__main__':
      root = Tk()
      app = App(root)