'How to get a file path using tkinter askopenfilename or other command?
I'm building a simple app, where it converts pdf to png.
When I use:
pdf_name = askopenfilenames(initialdir="/", title="Selecionar Arquivos")
I get:
print(pdf_name)
('C:/Users/user/Desktop/Apps/Python/Conversor img to pdf/file.pdf',)
So, the ask is:
How do I get this type?
print(pdf_name)
'C:/Users/user/Desktop/Apps/Python/Conversor img to pdf/file.pdf'
Solution 1:[1]
There are two ways to do that.
First
pdf_name = askopenfilenames(initialdir="/", title="Selecionar Arquivos")
print(pdf_name[0])
Second, Instead of askopenfilenames, you should try askopenfilename.
Also, Not Forget To Import this from tkinter.filedialog import askopenfilename.
pdf_name = askopenfilename(initialdir="/", title="Selecionar Arquivos")
print(pdf_name)
The output is same for both
'C:/Users/user/Desktop/Apps/Python/Conversor img to pdf/file.pdf'
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Sharim Iqbal |
