[英]Converting Python3 script to .exe with cx_Freeze, attribute error
在這里編寫我的第一個Python應用程序和我的第一篇文章。 我正在使用Python 3.7和cx_Freeze版本5.1.1運行Windows 10。
運行安裝程序版本並雙擊可執行文件后,出現錯誤:AttributeError:'NoneType'對象沒有屬性'write'。 我似乎無法自己弄清楚。
(也存在無法找到圖片的問題,因此我在腳本中將其注釋掉只是為了一次處理一個問題)
我不確定從哪里開始,我相信由於寫入文本框代碼而引發錯誤:
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()
感謝我可以獲得的任何幫助。 //弗雷德
弄清楚了。
導致此問題的是.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,並且可以正常工作。 :)
//弗雷德
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.