首页 > 解决方案 > 创建可执行的 tkinter

问题描述

我正在尝试使用TkinterPandasPillow等库创建代码的可执行文件。

我使用了pyinstllaercx_freezescipy出现错误或 .exe 的大小不符合您的要求(例如:500 mb)。

我想要的是一个可执行文件,能够在 Windows 和/或 MAC 中打开它以供大多数用户使用。

代码可能与这个问题无关,所以我需要或者也许我们需要所有都是可以理解的提示或教程才能创建可执行文件,因为在修改后的问题中,只有特定情况得到解决,而不是像我这样的常见情况描述 . 谢谢你。

这里我展示代码

import tkinter as tk
from tkinter import ttk
#from sismorresistente import *
from tkinter import messagebox
from PIL import Image
import pandas as pd
import os

class sismicidad():
    def __init__(self):
        self.vent_sismi = tk.Tk()
        self.vent_sismi.iconbitmap("sismo_ico_1.ico")
        self.vent_sismi.title("SISMICIDAD")
        self.pest_sismor = ttk.Notebook(self.vent_sismi)
        self.pest_sismor.grid(row=0, column = 0)
        self.sismorresistente_1()
        self.perf_suelos()
        self.zona_sismi()
        self.sismor_funcion()
        self.z_sismi_funcion()
        self.vent_sismi.mainloop()

#Funciones para la estructura de la pestaña SONAS SISMORRESISTENTE:
    def sismorresistente_1(self):
        ...
#Funcion de CERRAR:
    def cerrar_sismicidad(self):
        self.vent_sismi.destroy()

#Funciones para la estructura de la pestaña de PERFILES DE SUELOS:
    def perf_suelos(self):
        ...
    #Mostrar Tabla de Vs:
    def abrir_vs(self):
        self.im = Image.open("C:/Users/Miguel Mogollòn/Desktop/sismicidad/tabla_perf.jpg")
        self.im.show()

    #Funciones para PERFILES DE SUELOS:
    def sismor_funcion(self,event=None):

        self.x1=self.entry_1.get()

        try:
            self.x1=int(self.x1)

        except ValueError:
            messagebox.showwarning("Error", "Escribir solo números enteros.")

        while True:
            if self.x1 > 1500:
                self.eti_lab_11.configure(text="Perfil tipo S0: Roca Dura.", font = "helvetica 12", foreground= "blue")
                self.eti_lab_11.grid(row=3, column=0, padx=20, pady=10)

            elif self.x1 > 500 and self.x1 <= 1500:
                self.eti_lab_11.configure(text="Perfil tipo S1: Roca y Suelos muy rigidos.", font = "helvetica 12", foreground= "blue")
                self.eti_lab_11.grid(row=3, column=0, padx=20, pady=10)

            elif self.x1 > 180 and self.x1 <= 500:
                self.eti_lab_11.configure(text="Perfil tipo S2: Suelos Intermedios.", font = "helvetica 12", foreground= "blue")
                self.eti_lab_11.grid(row=3, column=0, padx=20, pady=10)

            elif self.x1 > 0 and self.x1 <= 180:
                self.eti_lab_11.configure(text="Perfil tipo S3: Suelos Blandos.", font = "helvetica 12", foreground= "blue")
                self.eti_lab_11.grid(row=3, column=0, padx=20, pady=10)

            elif self.x1 == 0:
                self.eti_lab_11.configure(text="")
                self.eti_lab_11.grid(row=3, column=0, padx=20, pady=10)

            break

#Funciones para la estrutura de la pestaña ZONAS SISMICAS:
    def zona_sismi(self, event=None):
        ...
    def abrir_norma(self):
        os.popen("C:/Users/Miguel Mogollòn/Desktop/sismicidad/norma_tecnica_e_030.pdf")

    def z_sismi_funcion(self, event=None):

        self.datos = pd.read_csv("C:/Users/Miguel Mogollòn/Desktop/sismicidad/distri_sism_1.csv", encoding="latin9", sep=";")
        self.df = pd.DataFrame(self.datos)

        self.x2 = self.entry_2.get()

        try:
            self.x2=str(self.x2)

        except ValueError:
            messagebox.showwarning("Error", "Escribir el distrito.")

        #while True:

        self.x2 = str.upper(self.x2)

        for self.idx in self.df.index:

            if self.df.DISTRITO[self.idx] == self.x2:
                self.eti_lab_14.configure(text = f"La zona sismica de '{self.x2}' es: {self.df.ZONA_SISMICA[self.idx]}", font="helvetica 12", foreground = "blue")
                #self.eti_lab_14.grid(row=1, column=1, padx=10, pady=10)
                self.eti_lab_14.place(x=30, y=70)
                break
        else:
            self.eti_lab_14.configure(text=f"Ingrese el distrito correcto",font="helvetica 12", foreground="blue")
            self.eti_lab_14.place(x=30, y=70)
            #self.eti_lab_14.grid(row=1, column=1, padx=10, pady=10)

aplicacion = sismicidad()

在这里,我展示了当我想打开可执行文件时会出现什么

在此处输入图像描述

标签: pythonpython-3.xtkinterscipypyinstaller

解决方案


在 python 版本 3.8 中,pyinstaller 有问题。如果通过 pip 直接安装没有帮助(pip install https://github.com/pyinstaller/pyinstaller/archive/develop.tar.gz),请尝试降级到 python 版本 3.7。


推荐阅读