[Tutor] apply() after class?

Kent Johnson kent37 at tds.net
Tue Feb 10 03:54:54 CET 2009


On Mon, Feb 9, 2009 at 5:33 PM, Wayne Watson
<sierra_mtnview at sbcglobal.net> wrote:
> Ah, another function without a link to a use. body, as in :
> (note that apply really is part of the class. It looked outside it earlier.)
>
> class SetDecoderDialog(tkSimpleDialog.Dialog):
>
>     def __init__(self, parent, gui):
>         self.gui = gui
>         tkSimpleDialog.Dialog.__init__(self, parent)
>
>     def body(self,master):
>         self.title("Set Video Decoder Register")
>
>         Label(master, text='Register:').grid(row=0, sticky=W)
>         Label(master, text='New Value:').grid(row=1, sticky=W)
>
>         self.reg = Entry(master, width=10)
>         self.val = Entry(master, width=10)
>
>         self.reg.grid(row=0, column=1, sticky=W)
>         self.val.grid(row=1, column=1, sticky=W)
>
>         return self.reg
>
>     def apply(self):
>         reg = eval(self.reg.get())
>         val = eval(self.val.get())
>         self.gui.SetDecoder( reg, val )
>
> That's the end of the class. Is there something going on here between
> body-apply and tkSimpleDialog? Making them available to it?

Apparently you are required to override body() when subclassing
tkSimpleDialog.Dialog, and optionally you can override apply() to
handle the results.
http://epydoc.sourceforge.net/stdlib/tkSimpleDialog.Dialog-class.html#body

Kent


More information about the Tutor mailing list