我正在用tkinter Python库创建一个应用程序,并且已经有了以下内容:
class Application(Tk) :
def __init__(self):
Tk.__init__(self)
self.Launch = Button(self, text="Launch", command=self.launchCallBack)
self.Browse = Button(self, text="Browse", command=self.browseCallBack)
self.pathlabel = Label(self)
self.file = ''
self.Launch.pack()
self.Browse.pack()
self.pathlabel.pack()
def browseCallBack(self) :
self.file = filedialog.askopenfile(parent=self, mode='rb', title='Choose a file', initialdir = "D:\\Users\T0211254\MyApp\Bundle CUD-CAPELLA 431\melody\eclipse\workspace", filetypes=[("aird Files", "*.aird")])
self.pathlabel.config(text=str(self.file))
def launchCallBack(self):
create_file(self.file)
问题是我的self.file
属性返回我:
<_io.BufferedReader name='MyFilePath'>
我只想恢复MyFilePath
。你知道吗
谢谢你的帮助!你知道吗
名称在
BufferedReader
的name
属性中可用,因此self.file.name
会得到您想要的。你知道吗但是,您可能希望改用
filedialog.askopenfilename()
,只获取名称,而不是打开的文件对象。你知道吗相关问题 更多 >
编程相关推荐