pyinstaller包GUI应用程序

时间:2017-07-07 12:08:35

标签: tkinter exe pyinstaller

我正在尝试打包我的应用程序作为独立的应用程序发送给人们。

我尝试通过输入以下命令来使用pyinstaller: pyinstaller --onefile TimeDomainAnalysis.py

这样就完成了,并给了我一个可执行文件,但它不会打开并返回附加的错误消息error message on double clicking the .exe

我的部分GUI代码(引用图片的位)如下:

from Tkinter import *
from PIL import Image, ImageTk
import tkMessageBox
from tkFileDialog import askopenfilename
import numpy as np
import matplotlib 
matplotlib.use('TkAgg')
from matplotlib.figure import Figure
import matplotlib.pyplot as plt
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg,         NavigationToolbar2TkAgg
from numpy import arange, sin, pi

# Each class is a frame in the root main window
class HomeFrame(object):
"""docstring for HomeFrame"""
def __init__(self, root):   # constructor places the widgets in the home     frame.  Each instance (self) is a new window placed in the main window
    super(HomeFrame, self).__init__()
    self.root=root      #oull the root window from the input constructor
    self.root.attributes("-topmost", False)
    self.root.title("Wave Analyzer App")
    self.Frame1=Frame(self.root)    #Create the home frame
    self.Frame1.pack()  #pack the frame.  It must be on a new line to be a     referencable object
    lab=Label(self.Frame1,text='Time Domain Wave Analyzer', font=("Helvetica", 30)).pack()  #label object within the frame that is not dynamic or to be passed to other instances

    self.But1=Button(self.Frame1,text='Get Started',command=self.B1Click)   #place a button in the frame
    self.But1.pack()

    path = "waves-circles-285359_960_720.jpg"

    #Creates a Tkinter-compatible photo image, which can be used everywhere Tkinter expects an image object.
    img = ImageTk.PhotoImage(Image.open(path))

    # load = Image.open("waves-circles-285359_960_720.jpg")
    # render = ImageTk.PhotoImage(load)
    IMLab=Label(self.Frame1,text='here i am',image=img)
    IMLab.image = img # You must keep a ref to the image else it gets destroyed!!
    IMLab.pack(side = "bottom", fill = "both", expand = "yes")
    lab2=Label(self.Frame1,text='By Ben Howey', font=("Helvetica", 12))     #label object within the frame that is not dynamic or to be passed to other instances
    lab2.pack(side=RIGHT)

1 个答案:

答案 0 :(得分:0)

解决:

添加

<div style="width:160px">
  <label>This is a short help <span>text <button>(?)</button></span></label>
</div>
<div style="width:170px">
  <label>This is a short help <span>text <button>(?)</button></span></label>
</div>
<div style="width:180px">
  <label>This is a short help <span>text <button>(?)</button></span></label>
</div>
<div style="width:190px">
  <label>This is a short help <span>text <button>(?)</button></span></label>
</div>
<div style="width:200px">
  <label>This is a short help <span>text <button>(?)</button></span></label>
</div>

在从exe运行时返回MEIPASS目录中的绝对文件路径,或者在Python中运行时返回绝对文件路径。然后通过编辑.spec文件将文件添加到包中以添加图像文件。