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

2024-09-24 00:31:38 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在用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。你知道吗

谢谢你的帮助!你知道吗


Tags: textselfinitdefbuttonlaunchcommandpack
1条回答
网友
1楼 · 发布于 2024-09-24 00:31:38

名称在BufferedReadername属性中可用,因此self.file.name会得到您想要的。你知道吗

但是,您可能希望改用filedialog.askopenfilename(),只获取名称,而不是打开的文件对象。你知道吗

相关问题 更多 >