Corrected code for PyShell, was:(Re: [Tutor] More Tkinter Help
Please [Dialog windows])
SA
sarmstrong13@mac.com
Tue, 18 Jun 2002 16:55:13 -0500
> This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.
--B_3107264114_2181541
Content-type: text/plain; charset="US-ASCII"
Content-transfer-encoding: 7bit
Ok. I found a bug. I left off all of the self descriptors on the buttons.
Here is the corrected code that now works the way I intended (my Bad):
#!/usr/bin/env python
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 = self.t1.get(0.0, END)
out = open(filename, 'w')
out.write(outfile)
out.close()
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=doSave)
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 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()
---
Thanks.
Sa
--B_3107264114_2181541
Content-type: text/html; charset="US-ASCII"
Content-transfer-encoding: quoted-printable
<HTML>
<HEAD>
<TITLE>Corrected code for PyShell, was:(Re: [Tutor] More Tkinter Help Pleas=
e [Dialog windows])</TITLE>
</HEAD>
<BODY>
<FONT FACE=3D"Verdana">Ok. I found a bug. I left off all of the self descript=
ors on the buttons. Here is the corrected code that now works the way I inte=
nded (my Bad):<BR>
#!/usr/bin/env python<BR>
from Tkinter import *<BR>
import os<BR>
import commands<BR>
import tkSimpleDialog<BR>
<BR>
class PyShell:<BR>
<BR>
def clearin(self):<BR>
&nb=
sp; self.t1.delete(0.0,END)<BR>
def clearout(self):<BR>
&nb=
sp; self.t2.delete(0.0,END)<BR>
def expyth(self):<BR>
&nb=
sp; self.t2.delete(0.0, END)<BR>
&nb=
sp; self.output =3D commands.getoutput(self.t1.get(0.0, END))=
<BR>
&nb=
sp; self.t2.insert(END, self.output)<BR>
def __init__(self, top):<BR=
>
&nb=
sp; def doSave():<BR>
&nb=
sp; SaveDia=
log =3D Saving(top)<BR>
&nb=
sp; filenam=
e =3D SaveDialog.getName()<BR>
&nb=
sp; outfile=
=3D self.t1.get(0.0, END)<BR>
&nb=
sp; out =3D o=
pen(filename, 'w')<BR>
&nb=
sp; out.wri=
te(outfile)<BR>
&nb=
sp; out.clo=
se()<BR>
&nb=
sp; self.t1 =3D Text(top, height=3D"12", width=3D"=
84", font=3D"Courier 12")<BR>
&nb=
sp; self.t1.pack(side=3DTOP, pady=3D2)<BR>
&nb=
sp; f =3D Frame(top)<BR>
&nb=
sp; f.pack()<BR>
&nb=
sp; self.b1 =3D Button(f, text=3D"Execute", command=3Ds=
elf.expyth)<BR>
&nb=
sp; self.b1.pack(side=3DLEFT)<BR>
&nb=
sp; self.b2 =3D Button(f, text=3D"Clear Input", comma=
nd=3Dself.clearin)<BR>
&nb=
sp; self.b2.pack(side=3DLEFT)<BR>
&nb=
sp; self.b3 =3D Button(f, text=3D"Clear Output", comm=
and=3Dself.clearout)<BR>
&nb=
sp; self.b3.pack(side=3DLEFT)<BR>
&nb=
sp; self.b4 =3D Button(f, text=3D"Save Input", comman=
d=3DdoSave)<BR>
&nb=
sp; self.b4.pack(side=3DLEFT)<BR>
&nb=
sp; self.t2 =3D Text(top, height=3D"12", width=3D"=
84", bg=3D"lightblue", font=3D"Courier 12")<BR>
&nb=
sp; self.t2.pack(side=3DTOP, pady=3D2)<BR>
<BR>
class Saving(tkSimpleDialog.Dialog):<BR>
<BR>
<BR>
def body(self, master): <BR=
>
&nb=
sp; Label(master, text=3D"Directory:").grid(row=3D0)<=
BR>
&nb=
sp; Label(master, text=3D"Filename:").grid(row=3D1)<B=
R>
&nb=
sp; self.e1 =3D Entry(master)<BR>
&nb=
sp; self.e2 =3D Entry(master)<BR>
&nb=
sp; self.e1.grid(row=3D0, column=3D1)<BR>
&nb=
sp; self.e2.grid(row=3D1, column=3D1)<BR>
&nb=
sp; return self.e1<BR>
def apply(self):<BR>
&nb=
sp; dir =3D self.e1.get()<BR>
&nb=
sp; fn =3D self.e2.get()<BR>
&nb=
sp; self.name =3D dir + fn<BR>
def getName(self):<BR>
&nb=
sp; return self.name<BR>
<BR>
<BR>
root =3D Tk()<BR>
app =3D PyShell(root)<BR>
root.mainloop()<BR>
<BR>
<BR>
---<BR>
Thanks.<BR>
Sa</FONT>
</BODY>
</HTML>
--B_3107264114_2181541--