Choose folder to save a file

2

I have this code that I select the place to save the file

    filename_2 = QFileDialog.getSaveFileName(self.dlg, "Select output file")
    self.dlg.pasta_saida.setText(filename_2)

But I would like to choose the folder to save the file inside how would it look?

    
asked by anonymous 07.01.2016 / 14:32

2 answers

3

If you want to choose where the file will be saved you can use the asksaveasfile method of the tkFileDielog module, just import the required libraries of TKinter .

Here is an example for you:

import Tkinter, tkFileDialog

def salvaarquivo(texto):
    f = tkFileDialog.asksaveasfile(mode="w", )#A foi opcao definida para escrita.
    if f is None:
        return
    f.write(texto)
    f.close()

salvaarquivo(raw_input("Digite um texto para ser salvo:"))

Documentation for tkFileDialog .

Font .

Note: If you do not have TKinter installed on your machine, you can download it and install it following the instructions of the TKinter site.

    
09.01.2016 / 21:09
0

You can try the following:

import TkInter, tkFileDialog
root = Tkinter.Tk()
dirNome = tkFileDialog.askdirectory(parent=root, initialdir="/",title ='Selecione a pasta')
    
07.01.2016 / 16:18