Paulo Roberto
Paulo Roberto

Reputation: 25

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'

Upvotes: 1

Views: 428

Answers (1)

Sharim09
Sharim09

Reputation: 6224

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'

Upvotes: 2

Related Questions