A Dangling Tk Entry

Rhodri James rhodri at wildebst.demon.co.uk
Tue Mar 10 05:48:27 CET 2009


On Tue, 10 Mar 2009 04:14:51 -0000, W. eWatson <notvalid2 at sbcglobal.net>  
wrote:

> Marc 'BlackJack' Rintsch wrote:
>> On Mon, 09 Mar 2009 04:22:57 -0700, W. eWatson wrote:
>>
>>> Marc 'BlackJack' Rintsch wrote:
>>>> On Sun, 08 Mar 2009 22:20:09 -0700, W. eWatson wrote:
>>>>
>>>>> You didn't answer my question why entry is necessary at all. The
>>>>> original author thought it was necessary to return entry. I'll give
>>>>> you a peek at a segment of the code I'm working with here:
>>>>>
>>>>> class Enter_Data_Dialog(tkSimpleDialog.Dialog):
>>>>>
>>>>>      def __init__(self, parent, sdict):
>>>>>          self.sdict = sdict
>>>>>          tkSimpleDialog.Dialog.__init__(self, parent)
>>>>>
>>>>>      def body(self,master):
>>>>>          self.title("Set a Number Entry Dialog")
>>>>>
>>>>>          Label( master, text="Number ").grid(row=0, sticky=W)
>>>>>          self.anumberVar = StringVar()
>>>>>          entry = Entry(master, width=10,
>>>>>   			textvariable=self.anumberVar).grid(row=0,
>>>> column=1)
>>>>>          self.anumberVar.set( "%d" % self.sdict["anumber"] )
>>>>>
>>>>>          return entry
>>>> `entry` is unnecessary here.  But that was not obvious from your
>>>> previous example, as you trimmed the code.  Now it is clear that
>>>> `entry` is always `None` because that's what `grid()` returns.
>>>>
>>>> But according to the docs this method should return the widget, that
>>>> should get the focus, so maybe the author really wanted to return the
>>>> `Entry` instance here, instead of `None`.
>>> He's got to return something, because he uses it upon return, as here:
>>  `entry` is always `None`, so it is the same as returning nothing  
>> because every function has an implicit ``return None`` at the end.
>>
>>>      def Set_Enter_Data(self):
>>>          sdict = {}
>>>          sdict[ "ok" ] = False
>>>          sdict[ "anumber" ] = self.anumber
>>>          dialog = Enter_Data_Dialog( self.master, sdict ) <---  
>>> returning
>>  That's not a call to the `body()` method so that ``return`` is  
>> irrelevant here.  Here an instance of `Enter_Data_Dialog` is created.   
>> No ``return`` involved.
>>  BTW if this is really just a dialog to enter a number, the functions  
>> `askinteger()` or `askfloat()` from the `tkSimpleDialog` module can be  
>> used.
>>  Ciao,
>> 	Marc 'BlackJack' Rintsch
> What you are seeing here as an example, is a paired down version of the  
> 2000 line program to focus on the particular problem at hand. The full  
> code uses up to 20 variable of various types, via the dialog object. It  
> uses them successfully to get the values the user has entered. How can  
> it be irrelevant if it works? The author thought this was the way to do  
> it. It's not my invention. It's no fluke. He does the same thing in  
> another dialog that brings back about 6 values.
>
>      def body(self,master):
[snip]

You're misunderstanding.  The line that you arrowed above has absolutely
nothing whatsoever to do with the method "body()", so keeping on showing
us ever fuller version of that isn't going to prove anything.  Now if
you were to show us a line like "something = dialog.body(something_else)"
then you might be onto something, but personally I suspect you're going
to find that rather hard.

-- 
Rhodri James *-* Wildebeeste Herder to the Masses



More information about the Python-list mailing list