python - Tkinter Password System -
i'm new using tkinter in python , i'm wondering if can me password system. i'm struggling when comes checking user entered username actual username, i'm not bothered password part @ point once have got username part working should easy enough adjust code username section. anyway here code:
#toms password system import tkinter tkinter import * tkinter import ttk username = ("tom") password = ("") usernameguess1 = ("") passwordguess1 = ("") #ignore file writing part,i'll sort out later. file = open("userlogondata.txt", "w") file.write("user data:\n") file = open("userlogondata.txt", "r") def trylogin(): print ("trying login...") if usernameguess == username: print ("complete sucsessfull!") messagebox.showinfo("-- complete --", "you have logged in.",icon="info") else: print ("error: (incorrect value entered)") messagebox.showinfo("-- error --", "please enter valid infomation!", icon="warning") #gui things window = tkinter.tk() window.resizable(width=false, height=false) window.title("log-in") window.geometry("200x150") window.wm_iconbitmap("applicationlogo.ico") #creating username & password entry boxes usernametext = tkinter.label(window, text="username:") usernameguess = tkinter.entry(window) passwordtext = tkinter.label(window, text="password:") passwordguess = tkinter.entry(window, show="*") usernameguess1 = usernameguess #attempt login button attemptlogin = tkinter.button(text="login", command=trylogin) usernametext.pack() usernameguess.pack() passwordtext.pack() passwordguess.pack() attemptlogin.pack() #main starter window.mainloop()
what doing wrong doesn't allow me check if user name correct ?
you need get
value entry widget:
if usernameguess.get() == username:
you should import need , use underscores in variable names:
from tkinter import messagebox, label, button, false, tk, entry username = ("tom") password = ("") def try_login(): print("trying login...") if username_guess.get() == username: messagebox.showinfo("-- complete --", "you have logged in.", icon="info") else: messagebox.showinfo("-- error --", "please enter valid infomation!", icon="warning") #gui things window = tk() window.resizable(width=false, height=false) window.title("log-in") window.geometry("200x150") #creating username & password entry boxes username_text = label(window, text="username:") username_guess = entry(window) password_text = label(window, text="password:") password_guess = entry(window, show="*") #attempt login button attempt_login = button(text="login", command=try_login) username_text.pack() username_guess.pack() password_text.pack() password_guess.pack() attempt_login.pack() #main starter window.mainloop()
you never close file after opening writing there chance experience behaviour not expect, close files after finished them or better again use with
open them.
Comments
Post a Comment