python - 创建可执行的 tkinter
问题描述
我正在尝试使用Tkinter、Pandas和Pillow等库创建代码的可执行文件。
我使用了pyinstllaer
,cx_freeze
但scipy
出现错误或 .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()
在这里,我展示了当我想打开可执行文件时会出现什么
解决方案
在 python 版本 3.8 中,pyinstaller 有问题。如果通过 pip 直接安装没有帮助(pip install https://github.com/pyinstaller/pyinstaller/archive/develop.tar.gz
),请尝试降级到 python 版本 3.7。
推荐阅读
- reactjs - 当我在同一个项目中单击两次时,为什么我的复选框不呈现?
- sqlalchemy - mssql (Azure Synapse SQL DW) 的 Alembic 主键问题
- tensorflow - 如何添加张量流损失函数?
- couchdb - 高效地填充新的 PouchDB 数据库
- visual-studio-code - 需要帮助调试 VSCode 中保存时的格式问题
- javascript - 反应:附加到 url 的文件名
- python - 使用数组检查深度嵌套的字典中的几乎等于(请阅读说明)
- python - testdriven.io django tdd - 运行 docker run 时出现错误:“$”不是有效的端口号
- django - django pytest 案例失败,而邮递员没有
- graphql - 使用 gatsby-source-contentful 使用 Gatsbyjs 和 Contentful 渲染富文本