ich möchte ein Loginprogramm für mein Computer schreiben und habe jetzt aber ein Problem: Ich habe den Code unten schon gemacht(aufs wesentliche gekürzt):
Code: Alles auswählen
from tkinter import *
root = Tk()
w, h = root.winfo_screenwidth(), root.winfo_screenheight()
root.overrideredirect(1)
root.geometry("%dx%d+0+0" % (w, h))
root.configure(bg="dark blue")
w2 = Label(root, justify=LEFT, fg = "red", bg = "dark green", padx = 1000, font = "Helvetica 32 bold italic", text="This compter is locked").pack(side="left")
w22 = Label(root, bg = "dark blue", fg = "red", text="Benutzername").place(x=100, y=530, width=300, height=30)
w23 = Label(root, bg = "dark blue", fg = "red", text="Passwort").place(x=1150, y=530, width=300, height=30)
def PasswortCheck_BenutzerCheck():
zahl = str(entryZahl.get())
benutzer = str(entryBenutzer.get())
if benutzer == "" and zahl == "":
root.destroy()
entryZahl = Entry(master=root, bg="green")
entryBenutzer = Entry(master=root, bg="green")
PasswortÜberprüfen = Button(master=root, text="Bestätigen", command=PasswortCheck_BenutzerCheck)
entryZahl.place(x=1150, y=500, width=300, height=30)
entryBenutzer.place(x=100, y=500, width=300, height=30)
PasswortÜberprüfen.place(x=630, y=640, width=150, height=20)
root.bind("<Return>", lambda e: PasswortCheck_BenutzerCheck())
root.mainloop()
Jetzt möchte ich, dass nach drei Fehlversuchen etwas passiert, aber das bekomme ich nicht hin.
Ich habe es auch schon so probiert:
Code: Alles auswählen
from tkinter import *
root = Tk()
w, h = root.winfo_screenwidth(), root.winfo_screenheight()
root.overrideredirect(1)
root.geometry("%dx%d+0+0" % (w, h))
root.configure(bg="dark blue")
w2 = Label(root, justify=LEFT, fg = "red", bg = "dark green", padx = 1000, font = "Helvetica 32 bold italic", text="This compter is locked").pack(side="left")
w22 = Label(root, bg = "dark blue", fg = "red", text="Benutzername").place(x=100, y=530, width=300, height=30)
w23 = Label(root, bg = "dark blue", fg = "red", text="Passwort").place(x=1150, y=530, width=300, height=30)
fehlversuche = 0
def PasswortCheck_BenutzerCheck():
zahl = str(entryZahl.get())
benutzer = str(entryBenutzer.get())
if fehlversuche == 3:
print("Aktion")
elif benutzer == "" and zahl == "":
root.destroy()
else:
fehlversuche = fehlversuche + 1
entryZahl = Entry(master=root, bg="green")
entryBenutzer = Entry(master=root, bg="green")
PasswortÜberprüfen = Button(master=root, text="Bestätigen", command=PasswortCheck_BenutzerCheck)
entryZahl.place(x=1150, y=500, width=300, height=30)
entryBenutzer.place(x=100, y=500, width=300, height=30)
PasswortÜberprüfen.place(x=630, y=640, width=150, height=20)
root.bind("<Return>", lambda e: PasswortCheck_BenutzerCheck())
root.mainloop()
Code: Alles auswählen
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\Tobias\AppData\Local\Programs\Python\Python38\lib\tkinter\__init__.py", line 1883, in __call__
return self.func(*args)
File "C:\Users\Tobias\Desktop\python\.py\Computer Pin\offi.py", line 23, in PasswortCheck_BenutzerCheck
if fehlversuche == 3:
UnboundLocalError: local variable 'fehlversuche' referenced before assignment
Wie bekomme ich es hin, dass es funktioniert?