小编Pus*_*keL的帖子

按下plot-Button后,cx_freeze转换的GUI-app(tkinter)崩溃

我几天来一直在处理这个问题,希望得到一些帮助.我开发了一个带有导入模块的GUI应用程序tkinter,numpy,scipy,matplotlib,它在python本身运行良好.转换为*.exe后,一切都按预期工作,但不是matplotlib部分.当我按下我定义的情节按钮时,*.exe只会关闭并且不显示任何情节.所以我想做一个简约的例子,我简单地绘制一个sin函数并且我面临同样的问题:在python中完美工作,当将它转换为*.exe时,它在按下情节按钮时崩溃.简约的例子在这里:

import tkinter as tk
import matplotlib.pyplot as plt
import numpy as np

class MainWindow(tk.Frame):
    def __init__(self):
        tk.Frame.__init__(self,bg='#9C9C9C',relief="flat", bd=10)
        self.place(width=x,height=y)
        self.create_widgets()

    def function(self):
        datax = np.arange(-50,50,0.1)
        datay = np.sin(datax)
        plt.plot(datax,datay)
        plt.show()

    def create_widgets(self):
        plot = tk.Button(self, text='PLOT', command=self.function)
        plot.pack()


x,y=120,300
root=tk.Tk()
root.geometry(str(x)+"x"+str(y))
app = MainWindow()
app.mainloop()
Run Code Online (Sandbox Code Playgroud)

并查看我的相应"setup.py"以使用cx_freeze进行转换.

import cx_Freeze
import matplotlib
import sys
import numpy
import tkinter

base = None

if sys.platform == "win32":
    base = "Win32GUI"

executables = [cx_Freeze.Executable("test.py", base=base)]


build_exe_options = {"includes":   ["matplotlib.backends.backend_tkagg","matplotlib.pyplot",
                             "tkinter.filedialog","numpy"],
                     "include_files":[(matplotlib.get_data_path(), "mpl-data")],
                     "excludes":[],
                    } …
Run Code Online (Sandbox Code Playgroud)

python tkinter matplotlib cx-freeze python-3.x

10
推荐指数
2
解决办法
8521
查看次数

标签 统计

cx-freeze ×1

matplotlib ×1

python ×1

python-3.x ×1

tkinter ×1