· 7 years ago · Feb 21, 2019, 09:32 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 TEXT 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'] = 0
44
45 myContainer1 = Frame(root)
46 myContainer1.pack()
47
48 button1 = Button(myContainer1) ### (1)
49 button1["text"]= "Dashboard" ### (2)
50 button1["background"] = "grey"
51 button1.pack()
52
53
54
55
56
57
58 else:
59 messagebox.showerror('Oops!','Username Not Found.')
60
61 def new_user(self):
62 #Establish Connection
63 with sqlite3.connect('quit.db') as db:
64 c = db.cursor()
65
66 #Find Existing username if any take proper action
67 find_user = ('SELECT * FROM user WHERE username = ?')
68 c.execute(find_user,[(self.username.get())])
69 if c.fetchall():
70 ms.showerror('Error!','Username Taken Try a Diffrent One.')
71 else:
72 messagebox.showinfo('Success!','Account Created!')
73 self.log()
74 #Create New Account
75 insert = 'INSERT INTO user(username,password) VALUES(?,?)'
76 c.execute(insert,[(self.n_username.get()),(self.n_password.get())])
77 db.commit()
78
79 #Frame Packing Methords
80 def log(self):
81 self.username.set('')
82 self.password.set('')
83 self.crf.pack_forget()
84 self.head['text'] = 'LOGIN'
85 self.logf.pack()
86 def cr(self):
87 self.n_username.set('')
88 self.n_password.set('')
89 self.logf.pack_forget()
90 self.head['text'] = 'Create Account'
91 self.crf.pack()
92
93
94
95 ################################################
96 def widgets(self):
97 self.head = Label(self.master,text = 'LOGIN',font = ('',25),pady = 10)
98 self.head.pack()
99 self.logf = Frame(self.master,padx =10,pady = 10)
100 Label(self.logf,text = 'Username: ',font = ('',20),pady=5,padx=5).grid(sticky = W)
101 Entry(self.logf,textvariable = self.username,bd = 5,font = ('',15)).grid(row=0,column=1)
102 Label(self.logf,text = 'Password: ',font = ('',20),pady=5,padx=5).grid(sticky = W)
103 Entry(self.logf,textvariable = self.password,bd = 5,font = ('',15),show = '*').grid(row=1,column=1)
104 Button(self.logf,text = ' Login ',bd = 3 ,font = ('',15),padx=5,pady=5,command=self.login).grid()
105 Button(self.logf,text = ' Create Account ',bd = 3 ,font = ('',15),padx=5,pady=5,command=self.cr).grid(row=2,column=1)
106 self.logf.pack()
107
108 self.crf = Frame(self.master,padx =10,pady = 10)
109 Label(self.crf,text = 'Username: ',font = ('',20),pady=5,padx=5).grid(sticky = W)
110 Entry(self.crf,textvariable = self.n_username,bd = 5,font = ('',15)).grid(row=0,column=1)
111 Label(self.crf,text = 'Password: ',font = ('',20),pady=5,padx=5).grid(sticky = W)
112 Entry(self.crf,textvariable = self.n_password,bd = 5,font = ('',15),show = '*').grid(row=1,column=1)
113 Button(self.crf,text = 'Create Account',bd = 3 ,font = ('',15),padx=5,pady=5,command=self.new_user).grid()
114 Button(self.crf,text = 'Go to Login',bd = 3 ,font = ('',15),padx=5,pady=5,command=self.log).grid(row=2,column=1)
115
116
117
118
119
120root=Tk()
121main(root)
122
123
124
125
126def infoAbout():
127 messagebox.showinfo("VaporBot", "Built on 2019 by Mr. Wagecuck")
128
129def warningLicense():
130 messagebox.showwarning("VaporBot License", "Free-License, Non registered")
131
132def exitBot():
133 value=messagebox.askquestion("Exit", "Do you want to exit this program?")
134
135 if value=="yes":
136 root.destroy()
137
138
139menuBar=Menu(root)
140root.config(menu=menuBar)
141
142fileFile=Menu(menuBar, tearoff=0)
143fileFile.add_separator()
144fileFile.add_command(label="Quit", command=exitBot)
145
146fileEdit=Menu(menuBar, tearoff=0)
147
148
149
150fileTools=Menu(menuBar, tearoff=0)
151
152
153
154fileHelp=Menu(menuBar, tearoff=0)
155fileHelp.add_command(label="License", command=warningLicense)
156fileHelp.add_separator()
157fileHelp.add_command(label="About", command=infoAbout)
158
159
160menuBar.add_cascade(label="File", menu=fileFile)
161menuBar.add_cascade(label="Edit", menu=fileEdit)
162menuBar.add_cascade(label="Tools", menu=fileTools)
163menuBar.add_cascade(label="Help", menu=fileHelp)
164
165
166
167root.title("VaporBot")
168miFrame=Frame(root, width=800, height=400)
169miFrame.pack()
170
171
172
173
174#___________PANTALLA_______________
175
176pantalla=Entry(miFrame)
177pantalla.config()
178
179
180#____________FILA1__________________
181
182
183
184
185
186
187root.mainloop()