SHARE
TWEET

Untitled

a guest Jun 25th, 2019 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from tkinter import *
  2. import sqlite3
  3. import os
  4.  
  5. def register(un, pw):
  6.     global register_screen
  7.     register_screen = Toplevel(main_screen)
  8.     register_screen.title("Register")
  9.     register_screen.geometry("300x250")
  10.  
  11.     global username, password, username_entry, password_entry
  12.  
  13.     username = StringVar()
  14.     password = StringVar()
  15.  
  16.     Label(register_screen, text="Please enter details below", bg="white").pack()
  17.     Label(register_screen, text="").pack()
  18.     username_lable = Label(register_screen, text="Username * ")
  19.     username_lable.pack()
  20.     username_entry = Entry(register_screen, textvariable=username)
  21.     username_entry.pack()
  22.     password_lable = Label(register_screen, text="Password * ")
  23.     password_lable.pack()
  24.     password_entry = Entry(register_screen, textvariable=password, show='*')
  25.     password_entry.pack()
  26.     Label(register_screen, text="").pack()
  27.     Button(register_screen, text="Register", width=10, height=1, bg="grey", command = register_user).pack()
  28.  
  29. def login():
  30.     global login_screen
  31.     login_screen = Toplevel(main_screen)
  32.     login_screen.title("Login")
  33.     login_screen.geometry("300x250")
  34.     Label(login_screen, text="Please enter details below to login").pack()
  35.     Label(login_screen, text="").pack()
  36.  
  37.     global username_verify
  38.     global password_verify
  39.  
  40.     username_verify = StringVar()
  41.     password_verify = StringVar()
  42.  
  43.     global username_login_entry
  44.     global password_login_entry
  45.  
  46.     Label(login_screen, text="Username * ").pack()
  47.     username_login_entry = Entry(login_screen, textvariable=username_verify)
  48.     username_login_entry.pack()
  49.     Label(login_screen, text="").pack()
  50.     Label(login_screen, text="Password * ").pack()
  51.     password_login_entry = Entry(login_screen, textvariable=password_verify, show= '*')
  52.     password_login_entry.pack()
  53.     Label(login_screen, text="").pack()
  54.     Button(login_screen, text="Login", width=10, height=1, command = login_verify).pack()
  55.  
  56. def register_user():
  57.  
  58.     username_info = username.get()
  59.     password_info = password.get()
  60.  
  61.     file = open(username_info, "w")
  62.     file.write(username_info + "n")
  63.     file.write(password_info)
  64.     file.close()
  65.  
  66.     username_entry.delete(0, END)
  67.     password_entry.delete(0, END)
  68.  
  69.     Label(register_screen, text="Registration Success", fg="green", font=("calibri", 11)).pack()
  70.  
  71. def login_verify():
  72.     username1 = username_verify.get()
  73.     password1 = password_verify.get()
  74.     username_login_entry.delete(0, END)
  75.     password_login_entry.delete(0, END)
  76.  
  77.     list_of_files = os.listdir()
  78.     if username1 in list_of_files:
  79.         file1 = open(username1, "r")
  80.         verify = file1.read().splitlines()
  81.         if password1 in verify:
  82.             login_sucess()
  83.             messagebox.showwarning('Message title', 'Message content')
  84.  
  85.         else:
  86.             password_not_recognised()
  87.  
  88.     else:
  89.         user_not_found()
  90.  
  91.  
  92. def login_sucess():
  93.     global login_success_screen
  94.     login_success_screen = Toplevel(login_screen)
  95.     login_success_screen.title("Success")
  96.     login_success_screen.geometry("150x100")
  97.     Label(login_success_screen, text="Login Success").pack()
  98.     Button(login_success_screen, text="OK", command=delete_login_success).pack()
  99.  
  100.  
  101. def password_not_recognised():
  102.     global password_not_recog_screen
  103.     password_not_recog_screen = Toplevel(login_screen)
  104.     password_not_recog_screen.title("Success")
  105.     password_not_recog_screen.geometry("150x100")
  106.     Label(password_not_recog_screen, text="Invalid Password ").pack()
  107.     Button(password_not_recog_screen, text="OK", command=delete_password_not_recognised).pack()
  108.  
  109.  
  110. def user_not_found():
  111.     global user_not_found_screen
  112.     user_not_found_screen = Toplevel(login_screen)
  113.     user_not_found_screen.title("Success")
  114.     user_not_found_screen.geometry("150x100")
  115.     Label(user_not_found_screen, text="User Not Found").pack()
  116.     Button(user_not_found_screen, text="OK", command=delete_user_not_found_screen).pack()
  117.  
  118.  
  119. def delete_login_success():
  120.     login_success_screen.destroy()
  121.  
  122.  
  123. def delete_password_not_recognised():
  124.     password_not_recog_screen.destroy()
  125.  
  126.  
  127. def delete_user_not_found_screen():
  128.     user_not_found_screen.destroy()
  129.  
  130.  
  131. def main_account_screen():
  132.     global main_screen, loginB, registerB
  133.     main_screen = Tk()
  134.     main_screen.geometry("300x250")
  135.     main_screen.title("Account Login")
  136.     Label(text="Select Your Choice", bg="white", width="300", height="2", font=("Calibri", 13)).pack()
  137.     Label(text="").pack()
  138.     loginB = Button(text="Login", height="2", width="30", command = login).pack()
  139.     Label(text="").pack()
  140.     registerB = Button(text="Register", height="2", width="30", command=register).pack()
  141.  
  142.     main_screen.mainloop()
  143.  
  144.  
  145. main_account_screen()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top