[Tutor] trying to put Tkinter widget handlers in a module

Alan Gauld alan.gauld at btinternet.com
Mon Sep 29 11:41:38 CEST 2008

<dwbarne at earthlink.net> wrote

>I am writing a large Python/Tkinter/Pmw program. It has become 
> so big that I would like to move some of the widget handlers 
> to a module for import. 

The normal way to factor a GUI is by class.
Move the entire class into a separate module. You cannot separate 
the methods of a class from the class definition.

You can define an event handler outside of a class and you could 
then put them into a separate module but then you lose access 
to the state information held by the class. Modularising by class 
makes much more sense.

It would be very unusual for a GUI class to be so big it needed to 
be split into separate modules. That would usually indicate that 
application logic was getting mixed in with the presentation logic 
of the GUI.


Alan Gauld
Author of the Learn to Program web site

More information about the Tutor mailing list