发电机正在限制
Generator is limiting
可以运行,TK设计没问题,但生成的代码仅限于一种类型。它当前在运行时所做的是弹出一个带有(复制和生成)按钮的 window、4 个单选按钮(低、中、强、强大)、长度下拉列表(8-32)和密码确实生成的输入框。
它目前只生成一种类型,因此如果您选择低,则生成的密码全部为小写,如果您选择中等,则全部为大写,强所有数字和强所有符号。
我想编辑使用大写、小写、数字、符号的组合,而不仅仅是一个
完整代码如下
# Python program to generate random
# password using Tkinter module
import random
import pyperclip
from tkinter import *
from tkinter.ttk import *
# Function for calculation of password
def low():
entry.delete(0, END)
# Get the length of password
length = var1.get()
digits = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0']
symbols = ['!', '@', '#', '$', '%', '^', '&', '*', '(', ')']
lower = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
upper = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
password = ""
# if strength selected is low
if var.get() == 1:
for i in range(0, length):
password = password + random.choice(lower)
return password
# if strength selected is medium
elif var.get() == 0:
for i in range(0, length):
password = password + random.choice(upper)
return password
# if strength selected is strong
elif var.get() == 3:
for i in range(0, length):
password = password + random.choice(digits)
return password
#if strength selected is powerful
elif var.get() == 2:
for i in range(0, length):
password = password + random.choice(symbols)
return password
else:
print("Please choose an option")
# Function for generation of password
def generate():
password1 = low()
entry.insert(10, password1)
# Function for copying password to clipboard
def copy1():
random_password = entry.get()
pyperclip.copy(random_password)
# Main Function
# create GUI window
root = Tk()
var = IntVar()
var1 = IntVar()
# Title of your GUI window
root.title("Random Password Generator")
# create label and entry to show
# password generated
Random_password = Label(root, text="Password")
Random_password.grid(row=0)
entry = Entry(root)
entry.grid(row=0, column=1)
# create label for length of password
c_label = Label(root, text="Length")
c_label.grid(row=1)
# create Buttons Copy which will copy
# password to clipboard and Generate
# which will generate the password
copy_button = Button(root, text="Copy", command=copy1)
copy_button.grid(row=0, column=2)
generate_button = Button(root, text="Generate", command=generate)
generate_button.grid(row=0, column=3)
# Radio Buttons for deciding the
# strength of password
# Default strength is Medium
radio_low = Radiobutton(root, text="Low", variable=var, value=1)
radio_low.grid(row=1, column=2, sticky='E')
radio_middle = Radiobutton(root, text="Medium", variable=var, value=0)
radio_middle.grid(row=1, column=3, sticky='E')
radio_strong = Radiobutton(root, text="Strong", variable=var, value=3)
radio_strong.grid(row=1, column=4, sticky='E')
radio_powerful = Radiobutton(root, text = "Powerful", variable = var, value = 2)
radio_powerful.grid(row = 1, column = 5, sticky = 'E')
combo = Combobox(root, textvariable=var1)
# Combo Box for length of your password
combo['values'] = (8, 9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20, 21, 22, 23, 24, 25,
26, 27, 28, 29, 30, 31, 32)
combo.current(0)
combo.bind('<<ComboboxSelected>>')
combo.grid(column=1, row=1)
# start the GUI
root.mainloop()
我试过第 43 行
password = password + random.choice(symbols) + random.choice(upper) + random.choice(lower)
#2nd try
password = password + random.choice(symbols, upper, lower)
这确实使用了大小写符号,但长度设置为 8,它生成了 24 个(每个 8 个)从好的方面来说,它确实随机地将它们放在示例中:(Dh$Yr!Gq$Hy $Zg@Fv&Uz@Af)
第二次尝试出错:
第 43 行,低
password = password + random.choice(symbols, upper, lower)
类型错误:Random.choice() 接受 2 个位置参数,但给出了 4 个
试试这个
password = password + random.choice(symbols + upper + lower)
或
password += random.choice(symbols + upper + lower)
这是你的完整代码>我正在写一条评论,我更改了我的代码。
# Python program to generate random
# password using Tkinter module
import random
import pyperclip
from tkinter import *
from tkinter.ttk import *
# Function for calculation of password
def low():
entry.delete(0, END)
# Get the length of password
length = var1.get()
digits = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0']
symbols = ['!', '@', '#', '$', '%', '^', '&', '*', '(', ')']
lower = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
upper = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
password = ""
# if strength selected is low
if var.get() == 1:
for i in range(0, length):
password = password + random.choice(lower) # for low security choose letters from lower
return password
# if strength selected is medium
elif var.get() == 0:
for i in range(0, length):
password = password + random.choice(lower+upper) # for medium security choose letters from lower and upper
return password
# if strength selected is strong
elif var.get() == 3:
for i in range(0, length):
password = password + random.choice(lower+upper+digits) # for strong security choose letters from lower, upper, and digits.
return password
#if strength selected is powerful
elif var.get() == 2:
for i in range(0, length):
password = password + random.choice(lower+upper+digits+symbols) # for powerful security choose letters from lower, upper, digits, and symbols.
return password
else:
print("Please choose an option")
# Function for generation of password
def generate():
password1 = low()
entry.insert(10, password1)
# Function for copying password to clipboard
def copy1():
random_password = entry.get()
pyperclip.copy(random_password)
# Main Function
# create GUI window
root = Tk()
var = IntVar()
var1 = IntVar()
# Title of your GUI window
root.title("Random Password Generator")
# create label and entry to show
# password generated
Random_password = Label(root, text="Password")
Random_password.grid(row=0)
entry = Entry(root)
entry.grid(row=0, column=1)
# create label for length of password
c_label = Label(root, text="Length")
c_label.grid(row=1)
# create Buttons Copy which will copy
# password to clipboard and Generate
# which will generate the password
copy_button = Button(root, text="Copy", command=copy1)
copy_button.grid(row=0, column=2)
generate_button = Button(root, text="Generate", command=generate)
generate_button.grid(row=0, column=3)
# Radio Buttons for deciding the
# strength of password
# Default strength is Medium
radio_low = Radiobutton(root, text="Low", variable=var, value=1)
radio_low.grid(row=1, column=2, sticky='E')
radio_middle = Radiobutton(root, text="Medium", variable=var, value=0)
radio_middle.grid(row=1, column=3, sticky='E')
radio_strong = Radiobutton(root, text="Strong", variable=var, value=3)
radio_strong.grid(row=1, column=4, sticky='E')
radio_powerful = Radiobutton(root, text = "Powerful", variable = var, value = 2)
radio_powerful.grid(row = 1, column = 5, sticky = 'E')
combo = Combobox(root, textvariable=var1)
# Combo Box for length of your password
combo['values'] = (8, 9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20, 21, 22, 23, 24, 25,
26, 27, 28, 29, 30, 31, 32)
combo.current(0)
combo.bind('<<ComboboxSelected>>')
combo.grid(column=1, row=1)
# start the GUI
root.mainloop()
可以运行,TK设计没问题,但生成的代码仅限于一种类型。它当前在运行时所做的是弹出一个带有(复制和生成)按钮的 window、4 个单选按钮(低、中、强、强大)、长度下拉列表(8-32)和密码确实生成的输入框。
它目前只生成一种类型,因此如果您选择低,则生成的密码全部为小写,如果您选择中等,则全部为大写,强所有数字和强所有符号。
我想编辑使用大写、小写、数字、符号的组合,而不仅仅是一个
完整代码如下
# Python program to generate random
# password using Tkinter module
import random
import pyperclip
from tkinter import *
from tkinter.ttk import *
# Function for calculation of password
def low():
entry.delete(0, END)
# Get the length of password
length = var1.get()
digits = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0']
symbols = ['!', '@', '#', '$', '%', '^', '&', '*', '(', ')']
lower = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
upper = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
password = ""
# if strength selected is low
if var.get() == 1:
for i in range(0, length):
password = password + random.choice(lower)
return password
# if strength selected is medium
elif var.get() == 0:
for i in range(0, length):
password = password + random.choice(upper)
return password
# if strength selected is strong
elif var.get() == 3:
for i in range(0, length):
password = password + random.choice(digits)
return password
#if strength selected is powerful
elif var.get() == 2:
for i in range(0, length):
password = password + random.choice(symbols)
return password
else:
print("Please choose an option")
# Function for generation of password
def generate():
password1 = low()
entry.insert(10, password1)
# Function for copying password to clipboard
def copy1():
random_password = entry.get()
pyperclip.copy(random_password)
# Main Function
# create GUI window
root = Tk()
var = IntVar()
var1 = IntVar()
# Title of your GUI window
root.title("Random Password Generator")
# create label and entry to show
# password generated
Random_password = Label(root, text="Password")
Random_password.grid(row=0)
entry = Entry(root)
entry.grid(row=0, column=1)
# create label for length of password
c_label = Label(root, text="Length")
c_label.grid(row=1)
# create Buttons Copy which will copy
# password to clipboard and Generate
# which will generate the password
copy_button = Button(root, text="Copy", command=copy1)
copy_button.grid(row=0, column=2)
generate_button = Button(root, text="Generate", command=generate)
generate_button.grid(row=0, column=3)
# Radio Buttons for deciding the
# strength of password
# Default strength is Medium
radio_low = Radiobutton(root, text="Low", variable=var, value=1)
radio_low.grid(row=1, column=2, sticky='E')
radio_middle = Radiobutton(root, text="Medium", variable=var, value=0)
radio_middle.grid(row=1, column=3, sticky='E')
radio_strong = Radiobutton(root, text="Strong", variable=var, value=3)
radio_strong.grid(row=1, column=4, sticky='E')
radio_powerful = Radiobutton(root, text = "Powerful", variable = var, value = 2)
radio_powerful.grid(row = 1, column = 5, sticky = 'E')
combo = Combobox(root, textvariable=var1)
# Combo Box for length of your password
combo['values'] = (8, 9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20, 21, 22, 23, 24, 25,
26, 27, 28, 29, 30, 31, 32)
combo.current(0)
combo.bind('<<ComboboxSelected>>')
combo.grid(column=1, row=1)
# start the GUI
root.mainloop()
我试过第 43 行
password = password + random.choice(symbols) + random.choice(upper) + random.choice(lower)
#2nd try
password = password + random.choice(symbols, upper, lower)
这确实使用了大小写符号,但长度设置为 8,它生成了 24 个(每个 8 个)从好的方面来说,它确实随机地将它们放在示例中:(Dh$Yr!Gq$Hy $Zg@Fv&Uz@Af)
第二次尝试出错: 第 43 行,低 password = password + random.choice(symbols, upper, lower) 类型错误:Random.choice() 接受 2 个位置参数,但给出了 4 个
试试这个
password = password + random.choice(symbols + upper + lower)
或
password += random.choice(symbols + upper + lower)
这是你的完整代码>我正在写一条评论,我更改了我的代码。
# Python program to generate random
# password using Tkinter module
import random
import pyperclip
from tkinter import *
from tkinter.ttk import *
# Function for calculation of password
def low():
entry.delete(0, END)
# Get the length of password
length = var1.get()
digits = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0']
symbols = ['!', '@', '#', '$', '%', '^', '&', '*', '(', ')']
lower = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
upper = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
password = ""
# if strength selected is low
if var.get() == 1:
for i in range(0, length):
password = password + random.choice(lower) # for low security choose letters from lower
return password
# if strength selected is medium
elif var.get() == 0:
for i in range(0, length):
password = password + random.choice(lower+upper) # for medium security choose letters from lower and upper
return password
# if strength selected is strong
elif var.get() == 3:
for i in range(0, length):
password = password + random.choice(lower+upper+digits) # for strong security choose letters from lower, upper, and digits.
return password
#if strength selected is powerful
elif var.get() == 2:
for i in range(0, length):
password = password + random.choice(lower+upper+digits+symbols) # for powerful security choose letters from lower, upper, digits, and symbols.
return password
else:
print("Please choose an option")
# Function for generation of password
def generate():
password1 = low()
entry.insert(10, password1)
# Function for copying password to clipboard
def copy1():
random_password = entry.get()
pyperclip.copy(random_password)
# Main Function
# create GUI window
root = Tk()
var = IntVar()
var1 = IntVar()
# Title of your GUI window
root.title("Random Password Generator")
# create label and entry to show
# password generated
Random_password = Label(root, text="Password")
Random_password.grid(row=0)
entry = Entry(root)
entry.grid(row=0, column=1)
# create label for length of password
c_label = Label(root, text="Length")
c_label.grid(row=1)
# create Buttons Copy which will copy
# password to clipboard and Generate
# which will generate the password
copy_button = Button(root, text="Copy", command=copy1)
copy_button.grid(row=0, column=2)
generate_button = Button(root, text="Generate", command=generate)
generate_button.grid(row=0, column=3)
# Radio Buttons for deciding the
# strength of password
# Default strength is Medium
radio_low = Radiobutton(root, text="Low", variable=var, value=1)
radio_low.grid(row=1, column=2, sticky='E')
radio_middle = Radiobutton(root, text="Medium", variable=var, value=0)
radio_middle.grid(row=1, column=3, sticky='E')
radio_strong = Radiobutton(root, text="Strong", variable=var, value=3)
radio_strong.grid(row=1, column=4, sticky='E')
radio_powerful = Radiobutton(root, text = "Powerful", variable = var, value = 2)
radio_powerful.grid(row = 1, column = 5, sticky = 'E')
combo = Combobox(root, textvariable=var1)
# Combo Box for length of your password
combo['values'] = (8, 9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20, 21, 22, 23, 24, 25,
26, 27, 28, 29, 30, 31, 32)
combo.current(0)
combo.bind('<<ComboboxSelected>>')
combo.grid(column=1, row=1)
# start the GUI
root.mainloop()