[Tutor] More Tkinter Help Please [Dialog windows]

alan.gauld@bt.com alan.gauld@bt.com
Wed, 19 Jun 2002 14:48:24 +0100


> I see what you mean.
> 
> To get the method to work your way, I have to change a few things in
> PyShell.__init__:
> 
>                 self.f = Frame(top)
>                 self.f.pack()

Correct, looks like you have it now.

> Another question. SaveText in self.saveText is a user defined method
> correct? 

Correct.

> It takes the text from the self.t1 object and loads 
> it into the filename object

More specifically the *file* object created when you use 
the filename *string* to open the file. Pedantics.

> PyShell instance has no attribute saveText.

Not until you define the method.

> The def methods in the class are attributes to the object class.
> Is this correct?

Absolutely. Classes have attributes which are either methods 
or data. Since functions in Python are objects too the method 
*names* are just attributes pointing to function objects...
In exactly the same way as the other attribbute names just 
point to raw data items. At that level there is very little 
difference between a method and a member data variable

> (He, He, he, he... This is so cool now.)(I love it when this 
> stuff starts to come together and make sense)

:-)
Looks like the light it coming on.

> So self defines the variables inside the defined object 
> attribute and allows those variables to be used outside 
> of the method and elsewhere in the class

Correct.

> Does this also allow the variable to be used outside the
> class, globally? 

No, because self is only visible inside the class definition.
Of course if you write a method that passes self back as a return value then
the reciever can use it to access the class:

class C:
  def f(self):
     print 'I'm f'
     return self
  def spam(self): print 'boo!')

c = C()
d = c.f()  # prints message and returns self
d.spam()   # prints boo! coz d and c now point to the same C instance

> Is this how we were able to pass the data 
> inside the apply class from MyDialog to PyShell by 
> using the return command?

We didn't. We kept a reference to the dialog when we created it 
then used that reference to call the getName() method. There was 
no need to pass anything back to the PyShell, it was all done 
by the PyShell requesting the data from the dialog. This is all 
good client-server style programming where the server(dialog here) 
performs tasks on demand from the client(pyshell here).  
This ensures that the dialog is reusable by other clients since 
it doesn't know who/what created/called it.

Alan g.
Author of the 'Learning to Program' web site
http://www.freenetpages.co.uk/hp/alan.gauld