<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<TITLE></TITLE>
<META content="MSHTML 6.00.2800.1400" name=GENERATOR></HEAD>
<BODY>
<DIV><FONT face=Arial color=#0000ff size=2></FONT> </DIV>
<BLOCKQUOTE dir=ltr
style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px solid;
MARGIN-RIGHT: 0px">
<DIV class=OutlookMessageHeader dir=ltr align=left><FONT face=Tahoma
size=2>-----Original Message-----<BR><B>From:</B> David Talaga
[mailto:dtalaga@novodynamics.com]<BR><B>Sent:</B> Tuesday, April 20, 2004
11:51 AM<BR><B>To:</B> Python Tutor<BR><B>Subject:</B> [Tutor] Tkinter
dilemas<BR><BR></FONT></DIV>
<P><FONT size=2>I am working with Tkinter and trying to create a box that
has
three buttons (in the Open() function) and these buttons seem to not
work. I am wondering what I am doing wrong. Here is all of the
code but I think that the problem lies within the Open function. The
first window pops up upon running the program but there is nothing in the
window. Can you help!!!</FONT></P>
<P><FONT color=#ff0000 size=2>#Created by dtalaga for Novo
Dynamics<BR>import
os<BR>from Tkinter import *<BR>import tkFileDialog<BR>import sys<BR>import
re<BR>import Tkinter</FONT></P>
<P><FONT color=#ff0000
size=2>#---------------------------------------------------------------------------------------<BR>#Define
all variables<BR>global root<BR>root=Tk()<BR>result = 0<BR>sub =
re.sub<BR>#---------------------------------------------------------------------------------------</FONT></P>
<P><FONT color=#ff0000 size=2># define the dialog function to call the
dialog
box <BR>def dialog():<BR>
root.withdraw()<BR> initDir =
'C:/windows/desktop'<BR> filetype = [('All files',
'.*')]<BR> fileName =
tkFileDialog.askopenfilename(initialdir=initDir,
filetypes=filetype)<BR> return fileName</FONT></P>
<P><FONT color=#ff0000
size=2>#---------------------------------------------------------------------------------------<BR>#Define
the doDialog function. Uses the dialog function from another file<BR>def
doDialog():<BR> global result<BR> result =
dialog()<BR>
<BR>#---------------------------------------------------------------------------------------<BR>#Define
the List function that displays the list of "cleaned" files<BR>def
Open():<BR> f = Tkinter.Button(root, text = "Find Files",
command
= Clean)<BR> f.pack()<BR> l = Tkinter.Button(root,
text = "View List", command = List)<BR> l.pack()<BR>
x
= Tkinter.Button(root, text = "Exit", command = sys.exit)<BR>
x.pack<SPAN class=740133816-20042004><FONT face=Arial
color=#0000ff> </FONT></SPAN></FONT></P>
<P><FONT color=#ff0000 size=2><SPAN class=740133816-20042004><FONT
face=Arial
color=#0000ff>Right here you forgot to put the parenthesis on
pack</FONT> </SPAN><BR>
<BR>#---------------------------------------------------------------------------------------<BR>#Define
function List to be used in the Open() function.<BR>def
List():<BR> S = Tkinter.Scrollbar()<BR> L =
Tkinter.Listbox()<BR> S.pack(side = Tkinter.RIGHT, fill =
Tkinter.Y)<BR> L.pack(side = Tkinter.LEFT, fill =
Tkinter.Y)<BR> S.config(command = L.yview)<BR>
L.config(yscrollcommand = S.set)</FONT></P>
<P><FONT color=#ff0000
size=2>#---------------------------------------------------------------------------------------<BR>#Define
function Clean. Clean will take the files and clean
them </FONT></P>
<P><FONT color=#ff0000 size=2>def Clean():<BR> if
f:<BR> fileName =
dialog()<BR> in_file =
open(fileName,'r').readlines()<BR>
out_file = open(fileName + '_cleaned.txt',
'w')<BR> for i in
in_file:<BR> tmp =
sub('\x0D','', i)<BR>
out_file.write(tmp)<BR> print 'File
cleaned'<BR>
<BR> if x:<BR>
out_file.close()<BR> if
l:<BR> List()<BR>
print
fileName</FONT></P>
<P><FONT color=#ff0000
size=2>#---------------------------------------------------------------------------------------<BR>#Call
the working functions<BR>#Open()</FONT></P>
<P><FONT size=2><SPAN class=740133816-20042004><FONT face=Arial
color=#0000ff> When I uncommented Open() it ran and showed the buttons
with the pack problem above it showed all
buttons </FONT></SPAN><BR></FONT><FONT color=#ff0000
size=2>
<BR>#---------------------------------------------------------------------------------------<BR>#Make
the path where the cleaned files will be stored<BR>if
os.path.isdir("C:\\Cleaned_Files"):<BR> print "C:\\Cleaned_Files
exists"<BR>else:<BR>
os.mkdir("C:\\Cleaned_Files")<BR>
<BR>#---------------------------------------------------------------------------------------
</FONT></P>
<P><FONT size=2><FONT
color=#ff0000>root.mainloop()<BR></FONT><BR><BR><BR>David
Talaga<BR>dtalaga@novodynamics.com<BR>734-205-9127 <SPAN
class=740133816-20042004><FONT face=Arial
color=#0000ff> </FONT></SPAN></FONT></P>
<P><FONT size=2><SPAN class=740133816-20042004></SPAN></FONT> </P>
<P><FONT face=Arial color=#0000ff size=2><SPAN class=740133816-20042004>Your
clean method will not work. Look on activestate for a shim recipie so
you can pass arguments with tkinter. Well I googled I
know there is one on AS but here is a url for another page. Look
this over you should be able to figure this out. I needed a similar
thing in the past.</SPAN></FONT></P>
<P><FONT face=Arial color=#0000ff size=2><SPAN class=740133816-20042004><A
href="http://www.astro.washington.edu/owen/TkinterSummary.html#CallbackShims">http://www.astro.washington.edu/owen/TkinterSummary.html#CallbackShims</A></SPAN></FONT></P>
<P><FONT face=Arial color=#0000ff size=2><SPAN class=740133816-20042004>Good
luck</SPAN></FONT><FONT size=2><SPAN
class=740133816-20042004> </SPAN></FONT></P></BLOCKQUOTE></BODY></HTML>
<P>-------------------------------------------------------------------------------------------<br>
***National City made the following annotations<br>
-------------------------------------------------------------------------------------------<br>
<br>
This communication is a confidential and proprietary business communication.
It is intended solely for the use of the designated recipient(s). If this
communication is received in error, please contact the sender and delete this
communication.<br>
===========================================================================================</P>