Python Forum
[Tkinter] How to get the name of a file only from a file path ?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] How to get the name of a file only from a file path ?
#3
I just found a way to do it but my attempt uses more lines of code.

Code:
def audio_file():
    global recorded_file
    recorded_file = filedialog.askopenfile(title='J.E.C. Software Solutions',
    filetypes=[('Image Files', ['.wav', '.mp3', '.vox'])])
    filepath = recorded_file
    path = Path(filepath)
    print(path.name)
Using this I receive:
expected str, bytes or os.PathLike object, not _io.TextIOWrapper
"Often stumped... But never defeated."
Reply


Messages In This Thread
RE: Stripping path before insert - by Yoriz - Jul-25-2019, 05:55 PM
RE: How to get the name of a file only from a file path ? - by DT2000 - Jul-25-2019, 06:27 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Video [PyQt] Get a executable file (.exe) from a .py file add a promoted class in a QWidget MiguelonReyes 0 762 Oct-17-2023, 11:43 PM
Last Post: MiguelonReyes
  Import a file and show file name on qcombobox GMCobraz 1 2,034 Jul-02-2020, 01:38 PM
Last Post: GMCobraz
  [Tkinter] Unable to get current contents of the entry field where the content is the file path pmpinaki 1 2,303 Apr-18-2020, 06:45 PM
Last Post: deanhystad
  [Tkinter] Tkinter - I need to read file excel from GUI app to script file johnjh 0 10,845 Apr-17-2020, 08:14 PM
Last Post: johnjh

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020