· 8 years ago · Aug 26, 2018, 04:38 PM
1from Tkinter import *
2import sqlite3
3import tkMessageBox
4import time
5
6class Start():
7 def __init__(self):
8 self.root = Tk()
9 self.root.geometry("300x200")
10 self.root.title("chat")
11 self.leb = Label(self.root, text="username:")
12 self.leb.place(x=20, y=20)
13 self.net = Label(self.root, text="password:")
14 self.net.place(x=20, y=40)
15 self.ley = Entry(self.root, )
16 self.ley.place(x=80, y=25)
17 self.ley2 = Entry(self.root, show="*")
18 self.ley2.place(x=80, y=45)
19 self.butt = Button(self.root, text="login", command=self.checkLogindata)
20 self.butt.place(x=165, y=95)
21 self.butt2 = Button(self.root, text="registration", command=self.registration)
22 self.butt2.place(x=15, y=95)
23 mainloop()
24
25 def registration(self):
26 self.root2 = Tk()
27 self.root2.geometry("400x200")
28 self.eny3 = Label(self.root2, text="first name")
29 self.eny3.place(x=20, y=20)
30 self.eny3 = Label(self.root2, text="lest name")
31 self.eny3.place(x=20, y=40)
32 self.eny3 = Label(self.root2, text="email")
33 self.eny3.place(x=20, y=60)
34 self.eny3 = Label(self.root2, text="password")
35 self.eny3.place(x=20, y=80)
36 self.eny3 = Label(self.root2, text="second password")
37 self.eny3.place(x=20, y=100)
38 self.br1 = Entry(self.root2)
39 self.br1.place(x=80, y=20)
40 self.br2 = Entry(self.root2)
41 self.br2.place(x=80, y=40)
42 self.br3 = Entry(self.root2)
43 self.br3.place(x=80, y=60)
44 self.br4 = Entry(self.root2, show="*")
45 self.br4.place(x=80, y=80)
46 self.br5 = Entry(self.root2, show="*")
47 self.br5.place(x=120, y=100)
48 self.butt3 = Button(self.root2, text="register", command=self.checkregisterion)
49 self.butt3.place(x=195, y=150)
50
51 def checkregisterion(self):
52 firstname = self.br1.get()
53 lesttname = self.br2.get()
54 email = self.br3.get()
55 password = self.br4.get()
56 password2 = self.br5.get()
57 self.conn = sqlite3.connect("myweb.db")
58 self.c = self.conn.cursor()
59 self.c.execute(
60 '''create table if not exists michael5(id integer primary key autoincrement, firstname varchar(100),lestname varchar(200), email varchar(200), friends varchar(255),password varchar(200),scuondpasssowrd varchar(200))''')
61
62 self.c.execute("insert into michael5(firstname,lestname,email,password,scuondpasssowrd) values " + str((firstname, lesttname, email, password, password2)))
63
64 sql = "select * from michael5"
65 self.c.execute(sql)
66 ssss = self.c.fetchall()
67 for u in ssss:
68 print u
69 self.conn.commit()
70 tkMessageBox._show("chat", "thank for registerion")
71
72 def checkLogindata(self):
73 self.userlog = self.ley.get()
74 passwordlog = self.ley2.get()
75 self.conn2 = sqlite3.connect("myweb.db")
76 self.cc = self.conn2.cursor()
77 fe = "select * from michael5 WHERE firstname = "
78 fe2 = "and password="
79 #print self.userlog
80 gg = self.userlog
81 gg2= passwordlog
82
83 da =self.cc.execute(fe + ("'"+gg+"'")+fe2+("'"+ gg2 +"'"))
84 da2 = self.cc.fetchone()
85 if da2 is None:
86 tkMessageBox._show("sorry", "the username or the password are not corrct")
87 else:
88 tkMessageBox._show("login", "you are login user "+ self.userlog)
89 self.chat_root()
90 for v in da:
91 print v
92
93
94 def chat_root(self):
95 self.root3 = Tk()
96 self.root3.geometry("700x800")
97 self.root3.title("chat login "+self.userlog)
98 self.searchbox = Entry(self.root3)
99 self.searchbox.place(x=500,y=40)
100 self.searchlebat = Label(self.root3, text="search:")
101 self.searchlebat.place(x=450,y=40)
102 self.searchbouttn = Button(self.root3, text="search", command=self.searchdbfriends)
103 self.searchbouttn.place(x=600,y=69)
104 self.searchlist = Listbox(self.root3,font=40)
105 self.searchlist.place(x=460,y=160)
106 self.searchlistleb = Label(self.root3, text="friends")
107 self.searchlistleb.place(x=460,y=140)
108 self.text = Text(self.root3,width=50)
109 self.text.place(x=0,y=0)
110
111
112 def searchdbfriends(self):
113 searchdata = self.searchbox.get()
114 self.conn3= sqlite3.connect("myweb.db")
115 self.ccc = self.conn3.cursor()
116 sql2 = "select firstname,email from michael5 WHERE firstname = "+ str("'"+searchdata+"'")
117 sql3 = "select firstname from michael5 WHERE firstname = "+ str("'"+searchdata+"'")
118 a2 = self.ccc.execute(sql2)
119 google = a2.fetchone()
120 if google is None:
121 tkMessageBox._show("chat", "the user not Existing")
122 af =tkMessageBox.askyesno("add this user",google)
123 if af == True:
124 print searchdata
125 print google
126 a3 = self.ccc.execute("insert into michael5(friends) values(" + str(searchdata) + ")")
127 for k in a3:
128 print k
129 if af == False:
130 pass
131
132f = Start()
133
134
135def main():
136 f
137
138
139main()