tkFileDialog closes main application
mdmdmd
mt_nich at yahoo.com
Wed Dec 20 12:37:10 EST 2006
Hello,
I wish to collect 4 files from a user. So I have decided to use
tkFileDialog askopenfilename. My problem is that after a few file
selections the root window is destroyed (the whole program just dissappears)
I have created a simple example and was able to reproduce the same thing
with this. I've just started using tkinter so I have no idea what I may
be doing wrong. If anyone has any ideas please let me know.
If you run the following code, just click the Browse button, and select
a file. Do this repeatedly and for me after the sixth or seventh time
the window shuts down.
BTW, I'm using python 2.4 on Windows XP. Thank you for any help.
################################################################################
from Tkinter import *
import Pmw
import tkFileDialog
import os.path
filepath = 'C:\\Documents and Settings\\admin\\Desktop\\'
class App(Frame):
def __init__(self,master):
Frame.__init__(self, master, bg='gray')
self.enttxt = StringVar()
lbl = Label(self,text='File 1:')
lbl.grid(row = 0,column = 0,sticky = W,padx = 5,pady = 5)
self.e1 = Entry(self,textvariable = self.enttxt,width = 50)
self.e1.grid(row = 0,column = 1,columnspan = 3,sticky = W,padx
= 5,pady = 5)
btn = Button(self,text='Browse ...',width = 12,
command = self.browse)
btn.grid(row = 0,column = 4,sticky=W,padx=5,pady=5)
def browse(self):
fileformats = [('Text File ','*.csv'),
('All Files ','*.*')]
retval = tkFileDialog.askopenfilename(title='Choose File',
initialdir=filepath,
filetypes=fileformats,
parent = self)
if retval:
self.enttxt.set(os.path.abspath(retval))
def main():
root = Tk()
root.withdraw()
root.title('test')
root.configure(bg='gray')
app = App(root)
app.pack()
root.update()
root.deiconify()
root.mainloop()
if __name__ == '__main__':
main()
More information about the Python-list
mailing list