Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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 :

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'
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading