[Tutor] Python question

alan.gauld@bt.com alan.gauld@bt.com
Fri Mar 28 13:10:01 2003


Caveat: I never use PMW so there might be a flaw in my reasoning!

> --------------------Class itself-----------------
> class EntryClass:
> 	EntryWidget = Pmw.EntryField(Frame2, ...
> 	def Callback(self): ...

Id define the class as a subclass oif the EntryWidget, like so:

class EntryClass(pmw.EntryWidget):
	def __init__(self, parent=0):
		pmw.EntryWidget.__init__(self,parent)
     
	def CallBack(self): ...as before...


Now you pass the parent in the constructoir as usual:

entry = EntryClass(frame2)

and dont need to access the internal member to configure:

entry.conmfigure(command = callback)
entry.pack(pady=25)

This is the power of inheritance. Also means you can create 
multiple independant entries whereas with your design they 
all share the same EntryWidget!

In fact you could even define the __init__ to take args* 
and pass the command parameter at creation:

entry = EntryClass(frame2, command=foo)
This
But using the Command class technique you seem to prefer 
that tends to get messy.

HTH,

Alan G.