[Tutor] Tkinter dilemas

Crabtree, Chad Chad.Crabtree at nationalcity.com
Tue Apr 20 12:42:01 EDT 2004


 

-----Original Message-----
From: David Talaga [mailto:dtalaga at novodynamics.com]
Sent: Tuesday, April 20, 2004 11:51 AM
To: Python Tutor
Subject: [Tutor] Tkinter dilemas



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 

Right here you forgot to put the parenthesis on 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()

 When I uncommented Open() it ran and showed the buttons with the pack
problem above it showed all buttons 
    
#---------------------------------------------------------------------------
------------
#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  

 

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.

http://www.astro.washington.edu/owen/TkinterSummary.html#CallbackShims
<http://www.astro.washington.edu/owen/TkinterSummary.html#CallbackShims> 

Good luck 


-------------------------------------------------------------------------------------------
***National City made the following annotations
-------------------------------------------------------------------------------------------

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.
===========================================================================================
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20040420/c56d1b9c/attachment.html


More information about the Tutor mailing list