Python 3.x TKInter filedialog does not return the extension chosen by the user

0

Hello:

I'm developing a GUI with TKInter where the user needs to enter a filename to save data. This file name can be from some specific extensions.

When the user opens the dialog to inform the name of the file (with tkinter.filedialog) and can inform the name with the extension. However, the feedback I receive is just what the user entered. If it just typed test instead of test.xml, even if it selected the XML file type, the return is always test. I also could not figure out how to get the extension selected by the user in the dialog.

I have already researched most of the traditional sources on TKInter, Google, Stack overflow in English and Portuguese, but I did not find anything about it.

My code is as follows (Python 3.6.4):

options = {
            'parent': self.appWindow,
            'title': 'Indique o arquivo para salvar os dados.',
            'filetypes': (("Arquivo XML", '*.xml'), ('Arquivo CSV', '*.csv'),('MS Excel', '*.xlsx'))#,
            #'confirmoverwrite': True
        }

        #selected = filedialog.asksaveasfilename(**options)
        #selected = filedialog.asksaveasfile(**options)
        #selected = filedialog.askopenfile(**options)
        selected = filedialog.askopenfilename(**options)
    
asked by anonymous 06.03.2018 / 13:33

0 answers