· 8 years ago · Dec 31, 2017, 10:18 PM
1from tkinter import *
2import tkinter as tk
3import sqlite3
4
5Conn = sqlite3.connect('Account Register.db')
6Curs = Conn.cursor()
7
8
9def create_table():
10 Curs.execute('CREATE TABLE IF NOT EXISTS Account_Details(username TEXT, password TEXT)')
11
12
13create_table()
14
15##########################
16class Screen():
17 def __init__(window, frame):
18
19 window.frame = frame
20 window.frame.title("Log in screen")
21 window.frame.geometry("650x300")
22 window.frame.configure(background="#00ffff")
23
24 window.titleLab = Label(window.frame, text="Enter your username \
25and password to login", font=("none", 16), bg="#00ffff")
26 window.titleLab.pack()
27
28 window.username = Label(window.frame, text="Username", bg="#00ffff")
29 window.username.pack()
30 window.entryUser = Entry(window.frame)
31 window.entryUser.pack()
32
33 window.password = Label(window.frame, text="Password", bg="#00ffff")
34 window.password.pack()
35 window.entryPass = Entry(window.frame)
36 window.entryPass.pack()
37
38 window.loginButton = Button(window.frame, text="Login", bg="white", command=window.grantAccess)
39 window.loginButton.pack(padx=8, pady=8)
40
41 window.createButton = Button(window.frame, text='Create account', bg='white', command=window.create_User)
42 window.createButton.pack() # Create user button. Function defined below, command defined here.
43
44 def grantAccess(window):
45 username = 'rat'
46 password = "guzarni"
47 userUsername = window.entryUser.get()
48 userPass = window.entryPass.get()
49 print(userUsername)
50 print(userPass)
51
52 if userUsername != username and userPass != password:
53 window.titleLab.configure(text="Invalid username and password. Please try again!")
54 window.entryUser.delete(0, END)
55 window.entryPass.delete(0, END)
56
57 if userUsername == username and userPass != password:
58 window.titleLab.configure(text="Invalid password, Please try again!")
59 window.entryUser.delete(0, END)
60 window.entryPass.delete(0, END)
61
62 if userUsername == username and userPass == password:
63 window.entryUser.destroy()
64 window.entryPass.destroy()
65 window.username.destroy()
66 window.password.destroy()
67 window.loginButton.destroy()
68 window.titleLab.configure(text="Welcome " + userUsername)
69
70 def create_User(window): # Button name to open new window
71 window.newWindow = tk.Toplevel(window.frame)
72 window.userPassScreen = pageTwo(window.newWindow)
73
74##########################
75class pageTwo:
76 def __init__(window, frame):
77 window.frame = frame
78 window.frame.title = ('create account screen')
79 window.frame.geometry("650x300")
80 window.frame.configure(background="#00ffff")
81
82 window.titleLab = Label(window.frame, text="Create your account", font=("none", 16), bg="#00ffff")
83 window.titleLab.pack()
84
85 window.user = Label(window.frame, text='Select a Username', bg='#00ffff', )
86 window.user.pack()
87 window.userEntry = Entry(window.frame)
88 window.userEntry.pack()
89 window.key = Label(window.frame, text='Select a Password', bg='#00ffff', )
90 window.key.pack()
91 window.passEntry = Entry(window.frame)
92 window.passEntry.pack()
93 window.keyConf = Label(window.frame, text='Confirm Password', bg='#00ffff', )
94 window.keyConf.pack()
95 window.keyEntry = Entry(window.frame)
96 window.keyEntry.pack()
97 window.conf = Button(window.frame, text='Confirm', bg='white', command=window.create_Account)
98 window.conf.pack()
99
100 window.close = Button(window.frame, text='Quit', bg='white', command=window.close_Window)
101 window.close.pack()
102
103 # pass Create account window through functions close window and
104 def close_Window(window):
105 window.frame.destroy()
106
107 def confirm(window):
108 window.newWin = tk.Toplevel(window.frame)
109 window.createAccScreen = pageThree(window.newWin)
110
111 def create_Account(window):***************************************************
112 userName = window.userEntry.get()
113 passWord = window.passEntry.get()
114 confirm_Pass = window.keyEntry.get()
115 while passWord != confirm_Pass:
116 window.titleLabel = Label(window.frame, text="Your passwords did not match", font=("none", 16),
117 bg="#00ffff")
118 if passWord == confirm_Pass:
119 Curs.execute('INSERT INTO Account_Details(username, Password) VALUES(?,?)', (userName, passWord,))
120 Conn.commit()
121
122##########################
123class pageThree():
124 def __init__(window, frame):
125 window.frame = frame
126 window.frame.title = ('Confirmation')
127 window.frame.geometry('250x100')
128 window.frame.configure(background='green yellow')
129
130 window.titleLab = Label(window.frame, text='Your account has successfully \n been created', font=('none', 12),
131 bg='green yellow')
132 window.titleLab.pack()
133
134 window.quitButton = Button(window.frame, text='OK', bg='white', command=window.close_Window)
135 window.quitButton.pack()
136
137 def close_Window(window):
138 window.frame.destroy()
139
140
141def main():
142 root = Tk()
143 userPassScreen = Screen(root)
144 root.mainloop()
145
146
147if __name__ == '__main__':
148 main()