[Tutor] Tkinter dilemas

David Talaga dtalaga at novodynamics.com
Tue Apr 20 11:51:28 EDT 2004


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!!!

#Created by dtalaga for Novo Dynamics
import os
from Tkinter import *
import tkFileDialog
import sys
import re
import Tkinter

#---------------------------------------------------------------------------
------------
#Define all variables
global root
root=Tk()
result = 0
sub = re.sub
#---------------------------------------------------------------------------
------------

# define the dialog function to call the dialog box
def dialog():
    root.withdraw()
    initDir = 'C:/windows/desktop'
    filetype = [('All files', '.*')]
    fileName = tkFileDialog.askopenfilename(initialdir=initDir,
filetypes=filetype)
    return fileName

#---------------------------------------------------------------------------
------------
#Define the doDialog function. Uses the dialog function from another file
def doDialog():
   global result
   result = dialog()

#---------------------------------------------------------------------------
------------
#Define the List function that displays the list of "cleaned" files
def Open():
   f = Tkinter.Button(root, text = "Find Files", command = Clean)
   f.pack()
   l = Tkinter.Button(root, text = "View List", command = List)
   l.pack()
   x = Tkinter.Button(root, text = "Exit", command = sys.exit)
   x.pack

#---------------------------------------------------------------------------
------------
#Define function List to be used in the Open() function.
def List():
   S = Tkinter.Scrollbar()
   L = Tkinter.Listbox()
   S.pack(side = Tkinter.RIGHT, fill = Tkinter.Y)
   L.pack(side = Tkinter.LEFT, fill = Tkinter.Y)
   S.config(command = L.yview)
   L.config(yscrollcommand = S.set)

#---------------------------------------------------------------------------
------------
#Define function Clean.  Clean will take the files and clean them

def Clean():
    if f:
       fileName = dialog()
       in_file = open(fileName,'r').readlines()
       out_file = open(fileName + '_cleaned.txt', 'w')
       for i in in_file:
         tmp = sub('\x0D','', i)
         out_file.write(tmp)
       print 'File cleaned'

    if x:
       out_file.close()
    if l:
       List()
    print fileName

#---------------------------------------------------------------------------
------------
#Call the working functions
#Open()



#---------------------------------------------------------------------------
------------
#Make the path where the cleaned files will be stored
if os.path.isdir("C:\\Cleaned_Files"):
   print "C:\\Cleaned_Files exists"
else:
   os.mkdir("C:\\Cleaned_Files")

#---------------------------------------------------------------------------
------------

root.mainloop()



David Talaga
dtalaga at novodynamics.com
734-205-9127
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20040420/be0e36e6/attachment.html


More information about the Tutor mailing list