如何将python文件编译成exe文件?

2024-05-23 18:33:24 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个.py文件和tkinter库中的下一个代码,我想把它转换成一个.exe文件,在任何Windows PC上执行它。当我用pyinstaller appname.py转换它时,它会生成带有builddist文件夹的.exe。但当我执行的时候,它什么也做不了。你知道吗

pyinstaller appname.pypyinstaller -F appname.py

from tkinter import *
import os
import subprocess
import time

raiz = Tk()

######################################################################

raiz.geometry("380x560+700+200")
raiz.title('EVA APP')
#raiz.config(bg="white")
raiz.iconbitmap('robot.ico')

######################################################################

# LOGO DANI
imagen1=PhotoImage(file="robot_dani.png")
Label(raiz, image=imagen1, justify=CENTER).grid(row=1, column=3, pady=20)

######################################################################

# DEFINICIONES
def test():
    print("FUNCIONA")

def TV():
    subprocess.Popen(['//cpd-sts/UsersSoftware/TeamViewer_Setup.exe'])

def chrome():
    subprocess.Popen(['//cpd-sts/UsersSoftware/ChromeSetup.exe'])

def impromptu():
    os.system("start chrome http://cpd-reporting:9191/_layouts/15/start.aspx#/SitePages/Instalar%20Impromptu.aspx")
    time.sleep(2)
    os.system("//cpd-sts/UsersSoftware/IBMiAccess6Release1/DVD-1/Windows/cwblaunch.exe")
    time.sleep(5)
    os.system("%windir%/syswow64/odbcad32.exe")
    time.sleep(2)
    os.system("mkdir %userprofile%/Desktop/Cognos")
    os.system("xcopy //cpd-sts/UsersSoftware/Cognos/* %userprofile%/Desktop/Cognos /e /i")
    time.sleep(2)
    os.system("msg * Ir a las propiedades de Setup > Compatibilidad > Cambiar la configuración para todos los usuarios > Ejectutar este programa en modo de compatibilidad para Windows XP. Ejecutar Setup > Siguiente > Siguiente...")
    os.system("xcopy //cpd-sts/UsersSoftware/Webs_Feina/Impromptu.lnk %userprofile%/Desktop /e /i")

#######################################################################

# BOTONES
botonTest=Button(raiz, text="TEST", command=test)
botonTest.grid(row=3, column=2, sticky="e", padx=4, pady=8)

botonTV=Button(raiz, text="Team Viewer", command=TV, activeforeground="white", activebackground="#3399ff")
botonTV.grid(row=4, column=2, sticky="e", padx=4, pady=8)

botonChrome=Button(raiz, text="Google Chrome", command=chrome)
botonChrome.grid(row=5, column=2, sticky="e", padx=4, pady=8)

botonImpromptu=Button(raiz, text="Instalar Impromptu", command=impromptu)
botonImpromptu.grid(row=6, column=2, sticky="e", padx=4, pady=8)

######################################################################

# Ejecución del programa en bucle
raiz.mainloop()

程序应该在窗口中使用tkinter执行,但该窗口不会出现。它什么也做不了。你知道吗


Tags: pyimporttimeosdefcolumnexesystem