[Tutor] More Tkinter Help Please

alan.gauld@bt.com alan.gauld@bt.com
Sun, 16 Jun 2002 22:43:45 +0100


> Yes I was able to figure the issue. It had to do with cut and pasting
> between a vi file and a bbedit file. I messed up my tabs. 

Interesting. That usually gives rise to a more explicit error 
about indenting. Howwever so ong as yuou fixed it... :-)

> I'm now working on the "save" button and am having a bit of 
> trouble. 

> Here is what I have so far:
> class PyShell:
>     def clearin(self):
>         self.t1.delete(0.0,END)
>     def expyth(self):
>         self.t2.delete(0.0, END)
>         self.output = commands.getoutput(self.t1.get(0.0, END))
>         self.t2.insert(END, self.output)

Just a wee point but as your GUIs get bigger this styule of t1,t2 etc will
get really hard to maintain. Its much better to name the control variables
aftyer their function, thus the above might become:

     def clearin(self):
         self.tInput.delete(0.0,END)
     def expyth(self):
         self.tOutput.delete(0.0, END)
         self.output = commands.getoutput(self.tInput.get(0.0, END))
         self.tOutput.insert(END, self.output)

This makes it clearer whats happening while keeping the first letter 
prefix to indicate what kind of widget is involved.


>     def __init__(self, top):
>         ....
>         self.b1 = Button(f, text="Execute", command=self.expyth)
similarly:
          self.bExec = Button(....

etc.


> class Saving(tkSimpleDialog.Dialog):
>         def savin(self, question):
>             Label(question, text="Directory:").grid(row=0)
>             Label(question, text="Filename:").grid(row=1)
>             self.e1 = Entry(question)
>             self.e2 = Entry(question)

and here:
              self.eDir = Entry(...
              self.eFile = Entry(...

makes it easier later to remember which Entry you want to read/modify.

> I think the problem is with:
> class Saving(tkSimpleDialog.Dialog):
> 
> Since this is not a child of the PyShell class and therefore is not
> inheriting from this class? 

Inheriting means that your class is the "same kind of thing" that the 
parent is. PyShell is an Application not a Dialog. If your Saving 
class is a type of Dialog (which I assume it is) then you are 
inheriting correctly.

But your Saving class has no init method so the widgets etc are 
not created etc. The 'savin' method would need to be called from 
somewhere but isn't. (Danny has also discussed the need to pass 
in a parent when you call the constructor). Without an init the 
class will be constructed using the inherited init from tkSimpleDialog
but it doesn't know about your savin method...

At least I think that's the problem, I've never actually used 
tkSimpleDialog in anger but thats how I remembwer it working!

Alan g