簡體   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