Next: 8. Fnorb tools Up: Fnorb - The Python Previous: 6.3 Using the BOA

# 7. Using Fnorb with `Tkinter' (Unix only)

This section describes how to use Fnorb in conjunction with the GUI toolkit `Tkinter'. In a nutshell, here is the problem. In server processes, Fnorb uses an event loop to listen for and dispatch operation requests. Unfortunately, Tk also uses an event loop to dispatch window events e.g. mouse movement, button up, button down. Obviously, if we want both Fnorb and Tk to respond in a sensible and timely manner, we must somehow combine the two event loops and have a single dispatcher delivering events to both systems.

The solution to this problem is to initialise Fnorb to use a special event dispatcher called the `TkReactor'. Here is an example taken from the file
```Fnorb/examples/tkinter/server.py`'':

First of all, we have to import the `TkReactor' module:

    # Fnorb modules.
    from Fnorb.orb import BOA, CORBA, TkReactor

    def main(argv):
        """ Do it! """

        print 'Initialising the ORB...'

        # Initialise the ORB.
        orb = CORBA.ORB_init(argv, CORBA.ORB_ID)

        print 'Initialising the Tk Reactor...'

And here is the single extra line of code that we have to add to make Fnorb and Tkinter work in perfect harmony.

        # Because we are using Tk, we must use the 'TkReactor' which
        # allows Tk and Fnorb events to be handled from within a single
        # event loop.
        #
        # The 'TkReactor' MUST be be initialised BEFORE the BOA.
        TkReactor.TkReactor_init()

        print 'Initialising the BOA...'

        # Initialise the BOA.
        boa = BOA.BOA_init(sys.argv, BOA.BOA_ID)

The rest of the program is the same for any other Fnorb server.

Next: 8. Fnorb tools Up: Fnorb - The Python Previous: 6.3 Using the BOA