-1
私は、Pythonでパスワードジェネレータとチェッカープログラムを作ろうとしています。現時点では私はguiを終了しましたが、tkinterのラベルを更新してtextvariableを表示するのに問題があります。単に「エラー」、「弱い」などの代わりに空白が表示されるため、他の人がジェネレータを助けてくれました。彼らがしたことは残念ながらこの場合にはうまくいかないでしょう。変数をtkinterの同じクラス内の異なる関数に呼び出す
class PageOne(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
label1 = tk.Label(self, text="Check your password", font=controller.title_font)
label1.pack(side="top", fill="x", pady=10)
entry = tk.Entry(self, bd =6)
button1 = tk.Button(self, text="Enter", command=checkPassword(entry.get()))
self.update
button2 = tk.Button(self, text="Back",
command=lambda: controller.show_frame("StartPage"))
label2 = tk.Label(self, text="Strength:", font=controller.title_font)
label3 = tk.Label(self, textvariable=passwordStrength, font=controller.title_font)
entry.pack()
button1.pack()
button2.pack()
label2.pack()
label3.pack()
def checkPassword(password):
passwordStrength = tk.StringVar()
strength = ['Password can not be Blank', 'Very Weak', 'Weak', 'Medium', 'Strong', 'Very Strong', 'Password must be less than 24 characters']
score = 1
print (password), len(password)
if len(password) == 0:
passwordStrength.set(strength[0])
return
if len(password) > 24:
passwordStrength.set(strength[6])
return
if len(password) < 4:
passwordStrength.set(strength[1])
return
if len(password) >= 8:
score += 1
if re.search("[0-9]", password):
score += 1
if re.search("[a-z]", password) and re.search("[A-Z]", password):
score += 1
if re.search(".", password):
score += 1
passwordStrength.set(strength[score])
私のプロジェクトの内容やその他のコードについて詳しく知りたい場合は、質問してください。すべての助けがありがとうございます:
あなたのコードを減らしたのはすばらしいことですが、[mcve]は完了する必要があります。私たちはコードを実行できるようにする必要があります。 –
私はちょうどすべてのコードを戻す必要がありますか? –
簡単に言えば、 'checkPassword'の' passwordStrength'名はそのメソッドに対してローカルであり、 '__init__'メソッドでは見えません。ところで、 'checkPassword'に' self' argがないので、 'password' argは実際には' self'と等価です。 –