problems subclassing a PMW widget

Martin Franklin martin.franklin at westgeo.com
Wed Dec 12 09:18:34 EST 2001


Laura Creighton wrote:

>> Greg Goodman:
>> Either I'm doing something wrong, or the Pmw widgets aren't meant to be
>> subclassed.  I'm hoping it's me.
> 
> I have very bad news for you.  I could never get it to work and
> neither could anybody else I talked to.  I hope you only need one


Laura,

Whats the problem with this?:-


import sys
import Tkinter
import Pmw

class UOMEntryField(Pmw.EntryField):
    """
    A Pmw.EntryField subclass
    """
    
    def __init__(self, parent = None, **kw):
        optiondefs = (
        ('command',           None,        None),
        ('errorbackground',   'pink',      None),
        ('invalidcommand',    self.bell,   None),
        ('labelmargin',       0,           Pmw.INITOPT),
        ('labelpos',          None,        Pmw.INITOPT),
        ('modifiedcommand',   None,        None),
        ('validate',          None,        self._validate),
        ('extravalidators',   {},          None),
        ('value',             '',          Pmw.INITOPT),
        )
        self.defineoptions(kw, optiondefs)
        
        Pmw.EntryField.__init__(self, parent, **kw)
        self.initialiseoptions(UOMEntryField)
        
        
if __name__ == '__main__':
    
    root = Tkinter.Tk()
    
    val = Tkinter.DoubleVar()
    val.set(1.23)
    
    widget = UOMEntryField(
    labelpos='w',
    label_text='My Label',
    validate='real',
    entry_textvariable = val)
    
    widget.pack()
    Tkinter.Button(text='Quit', command=sys.exit).pack()
    root.mainloop()

Martin




More information about the Python-list mailing list