单击生成按钮后,此应用程序中的标签不会显示密码。我认为它可能来自“for”循环。任何帮助,将不胜感激。
from tkinter import *
from tkinter import ttk
import random
window = Tk()
window.resizable(False , False)
window.title('Password Generator')
window.geometry('400x200')
length = IntVar()
lbl = StringVar()
var1 = StringVar()
Alphabet = 'qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM'
showpass = ttk.Label(window , textvariable = lbl).pack()
def randalp():
for i in range(length):
random.choice(Alphabet)
ttk.Label(window , text = 'Password Lentgh:').pack()
numchoosen = ttk.Combobox(window, width = 12 , textvariable = length)
numchoosen['values'] = (5,6,7,8,9,10)
numchoosen.pack()
numchoosen.current(2)
numchoosen.config(state = 'readonly')
rad1 = ttk.Checkbutton(window , text = 'Alphabet' , variable = var1).pack()
def btnclick():
get1 = var1.get()
if rad1 == '1':
lbl.set(randalp)
print(lbl)
btn = ttk.Button(window , text = 'Generate' , command = btnclick).pack()
window.mainloop()