Format for Python/Tkinter program
Russell E. Owen
no at spam.invalid
Fri Mar 21 18:59:06 EST 2003
I didn't read every word but basically it looks good to me.
I like the fact that you aren't doing "from Tkinter import *" and that
you are using SimpleCallback (aka currying functions) instead of using
lambdas.
Regarding packaging: I tend to have a separate module or package for
each widget, unless the widget is really simple. If a window or widget
is sufficiently complex, I create a separate file for each major
component, so I can easily test and work on each component separately.
For instance in a recent control interface for a complicated instrument
named DIS I created:
DIS (folder)
__init__.py contains "from DISWdg import *"
DISWdg.py the main widget that uses the other files in this package
Model.py a set of Tk variable-like things that contains current info
about DIS
ConfigInput.py the main set of input controls for setting the
configuration of DIS
ConfigWdg.py: combines ConfigInput.py and the main command buttons
Status.py a panel showing the status
I also make each widget into a subclass of Frame (or some other obvious
Tkinter class), so I can directly grid or pack it. For instance:
(file MyWdg.py):
import TkInter
class MyWdg(Tkinter.Frame):
def __init__(self, master, myWdg inputs, **kargs):
Tkinter.Frame.__init__(self, master, **kargs)
...do my own initialization
(another file):
import Tkinter
import MyWdg
root = Tk()
aWdg = MyWdg.MyWdg(root)
aWdg.pack()
# or get fancier and pack or grid several widgets together...
I hope you find PMW reliable. When I tried it on a Mac a year or two ago
I found some bugs and gave up on it. A pity, because it does a lot of
nice things.
In article <8761b8c9.0303211200.66811084 at posting.google.com>,
vicki at stanfield.net (Vandl) wrote:
>I am new to Python/Tkinter, having programmed quite a bit in C/Motif.
>I am trying to get a feel for the appropriate format for my new
>programs....
More information about the Python-list
mailing list