使用cx_Freeze将Python3脚本转换为.exe,属性错误

问题描述 投票:2回答:1

编写我的第一个Python应用程序和我的第一篇文章。我正在使用Python 3.7和cx_Freeze版本5.1.1运行Windows 10。

一旦我运行了安装程序构建,我双击我遇到的可执行文件错误:AttributeError:'NoneType'对象没有属性'write'。我似乎无法弄清楚自己。

(还有无法找到的图片有问题,所以我在脚本中评论它只是为了一次解决一个问题)

Tbh我不知道从哪里开始,我相信由于写入文本框代码而引发错误:

def decorator(func):
    def inner(inputStr):
        try:
            textbox.insert(INSERT, inputStr)
            return func(inputStr)
        except:
            return func(inputStr)
    return inner

sys.stdout.write=decorator(sys.stdout.write)

这是我创建的脚本。

from tkinter import *

from PIL import Image, ImageTk



root = Tk()
root.title("Ghost task")
root.geometry("640x640+0+0")

#Image load
#load = Image.open('Ghost.png')
#ghost = ImageTk.PhotoImage(load)

#img = Label(root, image=ghost)
#img.image = ghost
#img.place(x=0, y=0)

#Text

heading = Label(root, text="Finish workflow script", font =("arial", 20, "bold"), fg="steelblue").place(x=200, y=0)
label1 = Label(root, text="Provide the wf_group:", font =("arial", 12, "bold"), fg="steelblue").place(x=200, y=80)
label2 = Label(root, text="Provide the client:", font =("arial", 12, "bold"), fg="steelblue").place(x=200, y=103)
label3 = Label(root, text="Provide the user:", font =("arial", 12, "bold"), fg="steelblue").place(x=200, y=126)
label4 = Label(root, text="Provide the voucher no:", font =("arial", 12, "bold"), fg="steelblue").place(x=200, y=149)
bottom = Label(root, text="Version 1.01", font = ("arial", 6, "bold"), fg="black").place(x=580, y=625)

#Boxes

wfgroup = StringVar()
client = StringVar()
user = StringVar()
voucher = StringVar()
entry_box = Entry(root, textvariable=wfgroup, width=28, bg="lightgreen").place(x=445, y=85)
entry_box = Entry(root, textvariable=client, width=28, bg="lightgreen").place(x=445, y=107)
entry_box = Entry(root, textvariable=user, width = 28, bg="lightgreen").place(x=445, y=129)
entry_box = Entry(root, textvariable=voucher, width = 28, bg="lightgreen").place(x=445, y=151)




#Results

def do_mssql():
    textbox.delete('1.0', END)
    textbox.update()
    print("Removed some useless information")



def do_oracle():
    textbox.delete('1.0', END)
    textbox.update()
    print("Removed some useless information")


#Buttons
work = Button(root, text="MsSQL Buu", width=30, height=5, bg="pink", command=do_mssql).place(x=50, y=200)
work2 = Button(root, text="Oracle Buu", width=30, height=5, bg="pink", command=do_oracle).place(x=360, y=200)

#Text output

textbox=Text(root, width = 77, height = 20)
textbox.place(x=10, y=300)



def decorator(func):
    def inner(inputStr):
        try:
            textbox.insert(INSERT, inputStr)
            return func(inputStr)
        except:
            return func(inputStr)
    return inner

sys.stdout.write=decorator(sys.stdout.write)


root.mainloop()

感谢我能得到的任何帮助。 //弗雷德

python attributes cx-freeze
1个回答
0
投票

弄清楚了。

导致这个问题的是.write。我重写了一下脚本。不需要,但这就是我解决它的方式。

def do_mssql():
    textbox.delete('1.0', END)
    textbox.update()
    sys.stdout("--This script is for MsSQL--\n")



def redirector(inputStr):
    textbox.insert(INSERT, inputStr)

sys.stdout = redirector

从sys.stdout.write中删除.write将print()更改为sys.stdout并且它工作正常。 :)

//弗雷德

© www.soinside.com 2019 - 2024. All rights reserved.