我有一个代码,我想将其打包为EXE。程序包已完全打包,但是只要我运行它,它就会说
执行脚本失败
我的代码:
from tkinter import *
import tkinter.messagebox as tmsg
import string
import random
root = Tk()
def helpf():
tmsg.showinfo("How it works", "Enter the length of the password required\nThen select the strength of password\nClick the generate button to receive the password.\nClick on File->Save to Save the genrated Password")
def savefile():
f=open('/Passwords.txt', 'a')
f.write(pwd +'\n')
f.close()
def password():
global pwd
pwd=""
#pwd=str()
#pwd=""
value = str()
if (Lengthvalue.get()>16) or (Lengthvalue.get()==""):
Label(text="Please enter a correct password strength").grid(row=6,column=1)
if Weakvalue.get()==1:
value = string.ascii_letters
elif Moderatevalue.get()==1:
value = string.ascii_letters + string.digits
elif Strongvalue.get()==1:
value = string.ascii_letters + string.digits + '!?@#'
else:
Label(text="Please select Password Strength").grid(row=6,column=1)
if value!=str():
Label(text=" ").grid(row=6,column=1)
for x in range(0,Lengthvalue.get()):
pwd = pwd + random.choice(value)
Label(text=pwd,font=("Goodtimes",10, "bold")).grid(row=6, column=1)
#def password():
#print(Weakvalue, Moderatevalue, Strongvalue)
root.geometry("500x400")
root.minsize(500,400)
root.maxsize(500,400)
root.title("Random Password Generator")
#Heading
Label(text="Random Password Generator", bg="red", font=("Forte",15, "bold"),borderwidth=5, relief=RIDGE).grid(row=0, column=1)
#CheckBox
Lengthvalue=IntVar()
Weakvalue=IntVar()
Moderatevalue=IntVar()
Strongvalue=IntVar()
Label(text="Enter the length of\nPassword Required:\n(Between 8-16) ").grid(row=1, column=0)
Label(text="Select the Strength of\nPassword Required: ").grid(row=3, column=0)
Length=Entry(root, textvariable=Lengthvalue)
Weak=Checkbutton(text="Weak Password", variable=Weakvalue)
Moderate=Checkbutton(text="Moderate Password", variable=Moderatevalue)
Strong=Checkbutton(text="Strong Password", variable=Strongvalue)
Length.grid(row=1, column=1)
Weak.grid(row=3, column=1)
Moderate.grid(row=4, column=1)
Strong.grid(row=5, column=1)
#Generate Password Button
fr=Frame(root, borderwidth=3, bg="grey", relief=SUNKEN)
fr.grid(row=8, column=1)
b1=Button(fr, bg="white", text="Generate", command=password)
b1.grid(row=8, column=1)
#Adding Menus
mainmenu=Menu(root)
filemenu=Menu(mainmenu, tearoff=0)
filemenu.add_command(label="Save", command=savefile)
filemenu.add_separator()
filemenu.add_command(label="Exit", command=quit)
mainmenu.add_cascade(label="File", menu=filemenu)
root.config(menu=mainmenu)
helpmenu=Menu(mainmenu, tearoff=0)
helpmenu.add_command(label="How it works", command=helpf)
mainmenu.add_cascade(label="Help", menu=helpmenu)
root.config(menu=mainmenu)
root.mainloop()
这是一个随机密码生成器,它在.txt文件中创建并保存其答案,并将其保存在同一目录中。
Python 3.60版(已降级以使pyinstaller正常工作)
答案 0 :(得分:0)
令人惊讶的是!这东西对我有用
您需要使用此代码
pyinstaller password_generator.py --add-data passwords.txt