![](/img/trans.png)
[英]ResourceWarning: unclosed file <_io.BufferedReader name=4>
[英]Recover Path in <_io.BufferedReader name='Path'> after browsing a file Tkinter
我正在使用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()
来获取名称,而不是打开文件对象。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.