tkinter - retrieve file name during askopenfile

后端 未结 1 1599
死守一世寂寞
死守一世寂寞 2021-01-22 19:37

I have a text editor made with Python and tkinter.

This is my \'open file\' method:

def onOpen(self):
        file = askopenfile(filetypes=[(\"Text files         


        
相关标签:
1条回答
  • 2021-01-22 20:12

    You are passing the file object so you see the reference to the file object as the title, you can get the name from the file object with name = root.title(file.name).

    If you want just the base name use os.path.basename:

    import os
    name = os.path.basename(file.name)
    
    0 讨论(0)
提交回复
热议问题