[Tutor] More Tkinter Help Please [Dialog windows]

SA sarmstrong13@mac.com
Tue, 18 Jun 2002 16:37:59 -0500


Sorry. Forgot to cut and paste the final code:

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 __init__(self, top):
        def doSave():
            SaveDialog = Saving(top)
            filename = SaveDialog.getName()
            outfile = t1.get(0.0, END)
            out = open(filename, 'w')
            out.write(outfile)
            out.close()
        t1 = Text(top, height="12", width="84", font="Courier 12")
        t1.pack(side=TOP, pady=2)
        f = Frame(top)
        f.pack()
        b1 = Button(f, text="Execute", command=self.expyth)
        b1.pack(side=LEFT)
        b2 = Button(f, text="Clear Input", command=self.clearin)
        b2.pack(side=LEFT)
        b3 = Button(f, text="Clear Output", command=self.clearout)
        b3.pack(side=LEFT)
        b4 = Button(f, text="Save Input", command=doSave)
        b4.pack(side=LEFT)
        t2 = Text(top, height="12", width="84", bg="lightblue",
font="Courier 12")
        t2.pack(side=TOP, pady=2)

class Saving(tkSimpleDialog.Dialog):
    
    def body(self, master):
        Label(master, text="Directory:").grid(row=0)
        Label(master, text="Filename:").grid(row=1)
        self.e1 = Entry(master)
        self.e2 = Entry(master)
        self.e1.grid(row=0, column=1)
        self.e2.grid(row=1, column=1)
        return self.e1
    def apply(self):
        dir = self.e1.get()
        fn = self.e2.get()
        self.name = dir + fn
    def getName(self):
        return self.name

                   
root = Tk()
app = PyShell(root)
root.mainloop()