How to turn a .py into an .exe? [duplicate]

3

I have the following code:

#coding-utf-8
from Tkinter import Frame, Tk, BOTH, Text, Menu, END
import tkFileDialog
from tkinter import filedialog as fd
import dbf

class Example(Frame):

    def __init__(self, parent):
        Frame.__init__(self, parent)

        self.parent = parent
        self.initUI()

    def initUI(self):

        self.parent.title("Conversor de Arquivo DBF.")
        self.pack(fill=BOTH, expand=1)

        menubar = Menu(self.parent)
        self.parent.config(menu=menubar)

        fileMenu = Menu(menubar)
        fileMenu.add_command(label="Abrir", command=self.onOpen)
        menubar.add_cascade(label="Arquivo", menu=fileMenu)

        self.txt = Text(self)
        self.txt.pack(fill=BOTH, expand=1)


    def onOpen(self):
        ftypes = [('All files', '*')]
        dlg = tkFileDialog.Open(self, filetypes = ftypes)
        fl = dlg.show()
        if fl != '':
            text = self.readFile(fl)
            self.txt.insert(END, text)

    def readFile(self, fl):
        text = "Seu arquivo foi convertido corretamente e pronto para carregar no InCeres. O mesmo se encontra na" \
               "mesma pasta que foi importado"
        text2 = "Nao foram encontrados ocorrencia para serem corrigidas."
        mudou = False

        with dbf.Table(fl) as table:
            for field in ('sampleid', '__sampleid','_sampleid', 'n__samplei'):
                try:
                    table.rename_field(field, 'id')
                    mudou = True
                except Exception as e:
                    print(e)
                    pass

        if mudou:
            return text
        else:
            return text2




def main():
    root = Tk()
    ex = Example(root)
    root.geometry("300x250+300+300")
    root.mainloop()


if __name__ == '__main__':
    main()

I would like it to become an executable, ie open the window that was made for operations to be done, I tried to use py2exe , maybe wrongly ... it only generates the .exe that opens a windows console

How can I generate this?

    
asked by anonymous 08.11.2016 / 17:54

1 answer

3

Is your python 3? Py2exe does not work in python 3. For it, use Cx_freeze - link

    
13.11.2016 / 01:37