简体   繁体   中英

how do I solve the tkinter directory problem

I have a video file conversion code using tkinter and ffmpeg, but when using the tkinter command to get the folder directory it gives an error when it finds a folder that has separation between the words.

This is my code:

import os
import pathlib
import tkinter
from tkinter import filedialog
from tkinter import messagebox

filename = filedialog.askopenfilename()
path     = filedialog.askdirectory()

print(filename)
print(path)

#os.system('gif2webp ' + pa + ' -o ' + (pe + './Test.gif'))

os.system('ffmpeg -i {} {}'.format(filename, path))
messagebox.showinfo(title="Done", message="Done")

And it is this error that appears:

C:/Users/Administrador/Desktop/Test : No such file or directory

the path is incomplete, because there is a space in the folder name and he does not recognize the path, if you can help me I would be grateful.

You can do the same as you would do in a terminal. Use ""

os.system('ffmpeg -i "{}" "{}"'.format(filename, path))

Or , escape the spaces with \\ :

path = path.replace(" ", "\ ")

Or, use the newer and recommended subprocess module:

import subprocess
subprocess.run(["ffmpeg", "-i", filename, path])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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