tkFileDialog and os module help

Joined
Jun 17, 2011
Messages
1
Reaction score
0
I'm having some trouble with my script at the moment. I'm writing a program to bring up a dialog box to ask for the file, which works fine, then, using os.popen(<filename>) to open the file selected in a separate window. However, when I use the two together, as shown below, the os.popen doesn't run. But, if I just run os.popen('dir\\test.txt'), then the file will open properly.

####################################

import os
import tkFileDialog as fileOpen
from Tkinter import *

os.popen('D:\\test.txt') ## this bit works perfectly fine

def askOpen():
path = fileOpen.askopenfilename(title='Spreadsheet to open',initialdir='somedirectory',parent=root,filetypes=[('text docs','.txt'),('Excel Spreadsheets','.xls')]) ## as does this

print path ##this would print "somedirectory/fileSelected", as a string, exactly the format that should work in os.popen
os.popen(path) ## but this doesn't work...??

root = Tk()

Button(root,text='Open File',command=askOpen).pack()

root.mainloop()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top