· 7 years ago · Feb 20, 2019, 05:26 PM
1import sqlite3
2from tkinter import *
3from tkinter import messagebox
4
5
6
7
8
9###########################################################
10with sqlite3.connect('quit.db') as db:
11 c = db.cursor()
12
13c.execute('CREATE TABLE IF NOT EXISTS user (username TEXT NOT NULL ,password TEX NOT NULL);')
14db.commit()
15db.close()
16
17#main Class
18class main:
19 def __init__(self,master):
20 # Window
21 self.master = master
22 # Some Usefull variables
23 self.username = StringVar()
24 self.password = StringVar()
25 self.n_username = StringVar()
26 self.n_password = StringVar()
27 #Create Widgets
28 self.widgets()
29
30 #Login Function
31 def login(self):
32 #Establish Connection
33 with sqlite3.connect('quit.db') as db:
34 c = db.cursor()
35
36 #Find user If there is any take proper action
37 find_user = ('SELECT * FROM user WHERE username = ? and password = ?')
38 c.execute(find_user,[(self.username.get()),(self.password.get())])
39 result = c.fetchall()
40 if result:
41 self.logf.pack_forget()
42 self.head['text'] = self.username.get() + '\n Loged In'
43 self.head['pady'] = 400
44 else:
45 messagebox.showerror('Oops!','Username Not Found.')
46
47 def new_user(self):
48 #Establish Connection
49 with sqlite3.connect('quit.db') as db:
50 c = db.cursor()
51
52 #Find Existing username if any take proper action
53 find_user = ('SELECT * FROM user WHERE username = ?')
54 c.execute(find_user,[(self.username.get())])
55 if c.fetchall():
56 ms.showerror('Error!','Username Taken Try a Diffrent One.')
57 else:
58 messagebox.showinfo('Success!','Account Created!')
59 self.log()
60 #Create New Account
61 insert = 'INSERT INTO user(username,password) VALUES(?,?)'
62 c.execute(insert,[(self.n_username.get()),(self.n_password.get())])
63 db.commit()
64
65 #Frame Packing Methords
66 def log(self):
67 self.username.set('')
68 self.password.set('')
69 self.crf.pack_forget()
70 self.head['text'] = 'LOGIN'
71 self.logf.pack()
72 def cr(self):
73 self.n_username.set('')
74 self.n_password.set('')
75 self.logf.pack_forget()
76 self.head['text'] = 'Create Account'
77 self.crf.pack()
78
79
80
81 ################################################
82 def widgets(self):
83 self.head = Label(self.master,text = 'LOGIN',font = ('',35),pady = 10)
84 self.head.pack()
85 self.logf = Frame(self.master,padx =10,pady = 10)
86 Label(self.logf,text = 'Username: ',font = ('',20),pady=5,padx=5).grid(sticky = W)
87 Entry(self.logf,textvariable = self.username,bd = 5,font = ('',15)).grid(row=0,column=1)
88 Label(self.logf,text = 'Password: ',font = ('',20),pady=5,padx=5).grid(sticky = W)
89 Entry(self.logf,textvariable = self.password,bd = 5,font = ('',15),show = '*').grid(row=1,column=1)
90 Button(self.logf,text = ' Login ',bd = 3 ,font = ('',15),padx=5,pady=5,command=self.login).grid()
91 Button(self.logf,text = ' Create Account ',bd = 3 ,font = ('',15),padx=5,pady=5,command=self.cr).grid(row=2,column=1)
92 self.logf.pack()
93
94 self.crf = Frame(self.master,padx =10,pady = 10)
95 Label(self.crf,text = 'Username: ',font = ('',20),pady=5,padx=5).grid(sticky = W)
96 Entry(self.crf,textvariable = self.n_username,bd = 5,font = ('',15)).grid(row=0,column=1)
97 Label(self.crf,text = 'Password: ',font = ('',20),pady=5,padx=5).grid(sticky = W)
98 Entry(self.crf,textvariable = self.n_password,bd = 5,font = ('',15),show = '*').grid(row=1,column=1)
99 Button(self.crf,text = 'Create Account',bd = 3 ,font = ('',15),padx=5,pady=5,command=self.new_user).grid()
100 Button(self.crf,text = 'Go to Login',bd = 3 ,font = ('',15),padx=5,pady=5,command=self.log).grid(row=2,column=1)
101
102
103
104
105root=Tk()
106main(root)
107
108def infoAbout():
109 messagebox.showinfo("VaporBot", "Built on 2019 by Mr. Wagecuck")
110
111def warningLicense():
112 messagebox.showwarning("VaporBot License", "Free-License, Non registered")
113
114def exitBot():
115 value=messagebox.askquestion("Exit", "Do you want to exit this program?")
116
117 if value=="yes":
118 root.destroy()
119
120
121menuBar=Menu(root)
122root.config(menu=menuBar)
123
124fileFile=Menu(menuBar, tearoff=0)
125fileFile.add_separator()
126fileFile.add_command(label="Quit", command=exitBot)
127
128fileEdit=Menu(menuBar, tearoff=0)
129
130
131
132fileTools=Menu(menuBar, tearoff=0)
133
134
135
136fileHelp=Menu(menuBar, tearoff=0)
137fileHelp.add_command(label="License", command=warningLicense)
138fileHelp.add_separator()
139fileHelp.add_command(label="About", command=infoAbout)
140
141
142menuBar.add_cascade(label="File", menu=fileFile)
143menuBar.add_cascade(label="Edit", menu=fileEdit)
144menuBar.add_cascade(label="Tools", menu=fileTools)
145menuBar.add_cascade(label="Help", menu=fileHelp)
146
147
148
149root.title("VaporBot")
150miFrame=Frame(root, width=800, height=400)
151miFrame.pack()
152
153
154
155
156#___________PANTALLA_______________
157
158pantalla=Entry(miFrame)
159pantalla.config()
160
161
162#____________FILA1__________________
163
164
165
166
167
168
169root.mainloop()