开发者

Python file dialog issue

开发者 https://www.devze.com 2023-03-25 16:57 出处:网络
I am trying to use Tkinter to choose a file and then import that filename into an argument to pass in a function. The progra开发者_JAVA百科m simply stops after the file is chosen. I included a print s

I am trying to use Tkinter to choose a file and then import that filename into an argument to pass in a function. The progra开发者_JAVA百科m simply stops after the file is chosen. I included a print statement just to see if it returns the path and it does so I am not sure why it won't work in the function.

#Main

from Tkinter import *
import tkFileDialog


fileOpen = Tk()
fileOpen.withdraw() #hiding tkinter window

file_path = tkFileDialog.askopenfilename(title="Open file", filetypes=[("txt file",".txt"),("All files",".*")])

if file_path != "":
   print "you chose file with path:", file_path

else:
   print "you didn't open anything!"

master.quit()

print file_path   


spaceParser (file_path,'r','/Users/Desktop/TygerTygerParsed.txt','w')


This (shortened version) works just fine:

from Tkinter import *
import tkFileDialog

fileOpen = Tk()
fileOpen.withdraw() #hiding tkinter window

file_path = tkFileDialog.askopenfilename(
    title="Open file", filetypes=[("txt file",".txt"),("All files",".*")])

if file_path != "":
   print "you chose file with path:", file_path

else:
   print "you didn't open anything!"

print file_path   

So I'm guessing your program is halting on

master.quit()
0

精彩评论

暂无评论...
验证码 换一张
取 消