Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import *
- import os
- creds = 'temp.temp'
- credss = {}
- def signUp():
- global windowSignIn
- global entryLogin
- global entryPswd
- windowSignIn = Tk()
- windowSignIn.title('Sign up')
- instruction = Label(windowSignIn, text='Please enter new credidentials\n')
- instruction.grid(row=0, column=0, sticky=E)
- labelLogin = Label(windowSignIn, text='New login: ')
- labelLogin.grid(row=1, column=0, sticky=W)
- labelPswd = Label(windowSignIn, text='New password: ')
- labelPswd.grid(row=2, column=0, sticky=W)
- entryLogin = Entry(windowSignIn)
- entryLogin.grid(row=1, column=1)
- entryPswd = Entry(windowSignIn, show='*')
- entryPswd.grid(row=1, column=1)
- buttonSign = Button(windowSignIn, text='Sign up', command=bSignup)
- buttonSign.grid(columnspan=2, sticky=W)
- windowSignIn.mainloop()
- def bSignup():
- with open(creds, 'w') as f:
- f.write(entryLogin.get())
- f.write(':')
- f.write(entryPswd.get())
- f.write('\n')
- f.close()
- windowSignIn.destroy()
- logIn()
- def logIn():
- global entryLoginL
- global entryPswdL
- global windowLogin
- windowLogin = Tk()
- windowLogin.title('Login')
- instruction = Label(windowLogin, text='Log in!\n')
- instruction.grid(sticky=E)
- labelLoginL = Label(windowLogin, text='Login: ')
- labelLoginL.grid(row=1, sticky=W)
- labelPswdL = Label(windowLogin, text='Password: ')
- labelPswdL.grid(row=2, sticky=W)
- entryLoginL = Entry(windowLogin)
- entryLoginL.grid(row=1, column=1)
- entryPswdL = Entry(windowLogin, show='*')
- entryPswdL.grid(row=2, column=1)
- buttonLog = Button(windowLogin, text='Login', command=checkLogin)
- buttonLog.grid(columnspan=2, sticky=W)
- logOutB = Button(windowLogin, text="Logout", command=logOut)
- logOutB.grid(columnspan=2, sticky=E)
- windowLogin.mainloop()
- def checkLogin():
- with open(creds, 'r') as f:
- for line in f:
- user, pswd = line.strip().split(':')
- credss[user] = pswd
- username = entryLoginL.get()
- password = entryPswdL.get()
- r = Tk()
- r.title('Check')
- r.geometry('150x50')
- message = Label(r)
- if username in credss and credss[username] == password:
- message.configure(text="Logged in.")
- message.pack()
- r.mainloop()
- else:
- message.configure(text="Username and password don't match")
- message.pack()
- r.mainloop()
- def logOut():
- windowLogin.destroy()
- signUp()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement