Python文件对话框问题 [英] Python file dialog issue
本文介绍了Python文件对话框问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用Tkinter选择一个文件,然后将该文件名导入参数以传入一个函数。程序在选择文件后才会停止。我包含一个print语句,只是为了看看它是否返回路径,这样做,我不知道为什么它不会在函数中工作。
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')
推荐答案
版本)工作正常:
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()
这篇关于Python文件对话框问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文