[Tutor] More Tkinter Help Please [callbacks and embedded func tions]

alan.gauld@bt.com alan.gauld@bt.com
Mon, 17 Jun 2002 12:00:33 +0100


> So I guess my question is, if I have a program that has  
> these two calsses, how do I call the second class
> from a button that is defined and packed in the
> first class?

Thats easy. The first class can see the second class definition.
Therefore you can use the solution Danny shopwed you, namely 
create an event handler that instantiates the second class, 
passing parameters to the constructor as required.

> When the Save button is pushed in the dialog box, the the 
> second class will take the entries from the dialog box as 
> the absolute path to the save file and save the text from 
> the first text field in the first class 

You could do this by passing the text as a parameter to the 
Saver class in the constructor. However the conventional 
way to do this (as in How MS Word, IDLE etc do it) is to 
use the SaveAs dialog to obtain and test for validity the 
path/filename then make that available to the parent class
to actually save the data(since that PyShell class owns the 
data - it is responsible. The responsibility of the dialog 
is to find out *where* to save it)

This the Save method looks something like this:

def Save(self):
   SaveDialog = Saver(self)
   filepath = SaveDialog.path 
   f = open(filepath,'w')
   f.write(tOutput)
   f.close

Usually there is a way to call the SaveAs dialog modally such that 
it treturns a boolean result indicating whether a valid filename 
has been created. Check the tkSimpleDialog docs to see if such exists.

However I seem to recall that Tk has a standard SaveAs type dialog 
already built that mimics the platform(Windows or Unix) SaveAs dialog
so maybe you could use it.

HTH,

Alan G