Python file dialog issue

 ̄綄美尐妖づ 提交于 2019-12-12 02:26:34

问题


I am trying to use Tkinter to choose a file and then import that filename into an argument to pass in a function. The program 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')

回答1:


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()


来源:https://stackoverflow.com/questions/6904646/python-file-dialog-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!