Newbie Help Please.(OO and Tkinter)

paul colby spam at eatshit.net
Mon Jun 17 19:52:42 EDT 2002


SA wrote:

> 
> from Tkinter import *
> import os
> import commands
> import tkSimpleDialog
> 
> class PyShell:
> def clearin(self):
> self.t1.delete(0.0,END)
> def clearout(self):
> self.t2.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)
> def saving_callback():
> savin()
> def __init__(self, top):
> self.SAVE = Saving(self)
> self.t1 = Text(top, height="12", width="84", font="Courier 12")
> self.t1.pack(side=TOP, pady=2)
> f = Frame(top)
> f.pack()
> self.b1 = Button(f, text="Execute", command=self.expyth)
> self.b1.pack(side=LEFT)
> self.b2 = Button(f, text="Clear Input", command=self.clearin)
> self.b2.pack(side=LEFT)
> self.b3 = Button(f, text="Clear Output", command=self.clearout)
> self.b3.pack(side=LEFT)
> self.b4 = Button(f, text="Save Input", command=self.SAVE)
> self.b4.pack(side=LEFT)
> self.t2 = Text(top, height="12", width="84", bg="lightblue",
> font="Courier 12")
> self.t2.pack(side=TOP, pady=2)
> 
> 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)
> self.e1.grid(row=0, column=1)
> self.e2.grid(row=1, column=1)
> def apply(self):
> self.dir = self.e1.get()
> self.fn = self.e2.get()
> self.sav = self.dir + self.fn
> self.savfile = open(self.sav, "w")
> for line in self.t1.readlines():
> self.savefile.write(line)
> self.savefile.close()
> 
> 
> 
> root = Tk()
> app = PyShell(root)
> root.mainloop()
> 

Sure. I got a little further using

   self.SAVE = Saving(top)

which passes the correct parameter at least. 
Beyond this your code needs more work.

Regards
Paul Colby



More information about the Python-list mailing list