Python 创建可执行的tkinter

Python 创建可执行的tkinter,python,python-3.x,tkinter,scipy,pyinstaller,Python,Python 3.x,Tkinter,Scipy,Pyinstaller,我正在尝试用Tkinter、Pandas和Pillow等库创建代码的可执行文件 我使用了pyinstllaer、cx\u freeze和scipy,但是我得到了一个错误,或者.exe的大小与您想要的大小不符(例如:500 mb) 我想要的是一个可执行文件,能够在Windows和/或MAC中打开它,供大多数用户使用 代码可能与这个问题无关,所以我需要或者我们需要所有可以理解的技巧或教程来创建一个可执行文件,因为在修改后的问题中,只解决了特定的案例,而不是像我所描述的常见案例。多谢各位 这里我展示代

我正在尝试用Tkinter、Pandas和Pillow等库创建代码的可执行文件

我使用了
pyinstllaer
cx\u 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()
将tkinter作为tk导入
从tkinter导入ttk
#从Sismoresistente进口*
从tkinter导入消息框
从PIL导入图像
作为pd进口熊猫
导入操作系统
类sismicidad():
定义初始化(自):
self.vent_sismi=tk.tk()
self.vent\u sismi.iconbitmap(“sismo\u ico\u 1.ico”)
自排气口名称(“SISMICIDAD”)
self.pest\u sismor=ttk.Notebook(self.vent\u sismi)
self.pest_sismor.grid(行=0,列=0)
self.sismorresistente_1()
self.perf_suelos()
self.zona_sismi()
self.sismor_函数()
self.z_sismi_函数()
self.vent_sismi.mainloop()
#西斯莫雷斯坦特瘟疫机构职能:
def SISMORRESISTANTE_1(自身):
...
#CERRAR职能:
def cerrar_sismicidad(自我):
self.vent_sismi.destroy()
#苏伊洛群岛鼠疫机构职能:
def性能(自我):
...
#莫斯特拉塔布拉酒店
def abrir_vs(自身):
self.im=Image.open(“C:/Users/Miguel Mogollòn/Desktop/sismicidad/tabla_perf.jpg”)
self.im.show()
#苏伊洛斯总统职能:
def sismor_函数(自身,事件=无):
self.x1=self.entry_1.get()
尝试:
self.x1=int(self.x1)
除值错误外:
messagebox.showwarning(“错误”,“Escribir solo números enteros.”)
尽管如此:
如果self.x1>1500:
self.eti_lab_11.configure(text=“Perfil tipo S0:Roca Dura.”,font=“helvetica 12”,front=“blue”)
self.eti_lab_11.grid(行=3,列=0,padx=20,pady=10)

如果python版本3.8中的self.x1>500和self.x1 180以及self.x1 0和self.x1,pyinstaller就会出现问题。如果通过pip直接安装没有帮助(
pip安装https://github.com/pyinstaller/pyinstaller/archive/develop.tar.gz
),尝试降级到python版本3.7。

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

我使用
pyinstaller
平台将其编译成可执行文件,并在CMD窗口中显示代码:

pip install auto-py-to-exe

决心!!谢谢

我使用
pyinstaller
平台将其编译成可执行文件,并在CMD窗口中显示代码:

pip install auto-py-to-exe

决心!!谢谢

什么python版本?是Python3.8吗?@DYB是的,是Python3.7。pyinstaller有问题吗?或者你只是想知道怎么做?如果有问题,您可以设置错误吗?发生的情况是,我在使用
scipy
(平台)创建可执行文件时没有收到错误;可执行文件已创建,但在打开可执行文件时(我使用
tkinter
),cmd窗口会出现并消失。我使用pyinstaller始终为带有tkinter的windows创建.exe。你确定“代码可能与此问题无关”吗?可能是代码或命令中有什么东西导致了这个问题。什么python版本?是Python3.8吗?@DYB是的,是Python3.7。pyinstaller有问题吗?或者你只是想知道怎么做?如果有问题,您可以设置错误吗?发生的情况是,我在使用
scipy
(平台)创建可执行文件时没有收到错误;可执行文件已创建,但在打开可执行文件时(我使用
tkinter
),cmd窗口会出现并消失。我使用pyinstaller始终为带有tkinter的windows创建.exe。你确定“代码可能与此问题无关”吗?可能是代码或命令中有什么东西导致了这个问题。