繁体   English   中英

浏览文件Tkinter后在<_io.BufferedReader name ='Path'>中恢复路径

[英]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

感谢您的帮助!

该名称在BufferedReadername属性中可用,因此self.file.name会为您提供所需的内容。

但是,您可能想改用filedialog.askopenfilename()来获取名称,而不是打开文件对象。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM