· 4 years ago · Aug 24, 2021, 11:20 PM
1from tkinter import *
2from tkinter import messagebox
3import os
4import sqlite3
5from tkinter import scrolledtext
6
7window = Tk()
8window.geometry("400x250")
9window.configure(bg='lightgreen')
10# chechk = Checkbutton(o).place(x= 150, y = 100)
11con = sqlite3.connect("data.bd")
12c = con.cursor()
13c.execute(""" CREATE TABLE if not exists wards(
14 name TEXT,
15 passoword TEXT,
16 email TEXT,
17 note TEXT )
18
19 """)
20con.commit()
21
22
23def moomar():
24 make_account_window = Tk()
25 make_account_window.geometry("400x250")
26 make_account_window.configure(bg='lightgreen')
27
28 name_entry = Entry(make_account_window, width='30')
29 name_entry.place(x=110, y=0) # .place(x=10,y)
30 label_name = Label(make_account_window, text='Name', width='7', bg='lightgreen').place(x=50, y=0)
31
32 email_entry = Entry(make_account_window, width='30')
33 email_entry.place(x=110, y=20)
34 email_label = Label(make_account_window, text='Email', width='7', bg='lightgreen').place(x=50, y=20)
35
36 passoward_entry = Entry(make_account_window, width='30')
37 passoward_entry.place(x=110, y=40)
38 passoward_label = Label(make_account_window, text='Passoward', width='7', bg='lightgreen').place(x=50, y=40)
39
40 # def
41 def add():
42 email = email_entry.get()
43 passoward = passoward_entry.get()
44 name = name_entry.get()
45 if name == '':
46 messagebox.showinfo('Alert', 'please write your name')
47 elif email == '':
48 messagebox.showinfo('Alert', 'please write your email')
49 elif passoward == '':
50 messagebox.showinfo('Alert', 'please write your passoward')
51 else:
52 pass
53
54 con = sqlite3.connect('data.bd')
55 c = con.cursor()
56 c.execute("INSERT INTO wards VALUES(:email,:name,:passoward,:note)",
57
58 {
59 'email': email_entry.get(),
60 'name': name_entry.get(),
61 'passoward': passoward_entry.get(),
62 'note': 'mom'
63
64 })
65 con.commit()
66 con.close()
67 name_entry.delete(0, END)
68 email_entry.delete(0, END)
69 passoward_entry.delete(0, END)
70 # if
71 # new window
72 note_window = Tk()
73 note_window.geometry('600x600')
74 note_window.configure(bg='lightgreen')
75 ##########################################
76 text_note = scrolledtext.ScrolledText(note_window, font=('Times New Roman', 30), width='20', height='10')
77 text_note.place(x=10, y=5)
78 ###########################################
79 note_window.mainloop()
80
81 # buttons
82 enter_button_in_make = Button(make_account_window, text='Enter', bg='lightblue', width='10', command=add)
83 enter_button_in_make.place(x=150, y=150)
84
85
86# c.execute('''CREATE TABLE stocks(
87# date text, trans text)''')
88
89
90def login():
91 if e_name.get() == '' or e_passward.get() =='':
92 messagebox.showerror("Error","All Fields Are Required")
93
94 else:
95 try:
96 con = sqlite3.connect("data.bd")
97 c = con.cursor()
98 c.execute("SELECT note FROM wards WHERE name =? AND passoword = ?",
99 [str(e_name.get()), str(e_passward.get())])
100 # note window
101 note_window = Tk()
102 note_window.geometry('633x520')
103 note_window.configure(bg='lightgreen')
104 # scrolledtext
105 text_note = scrolledtext.ScrolledText(note_window, font=('Times New Roman', 30), width='30', height='10')
106 text_note.place(x=10, y=50)
107 #insert the text in the note_text
108 row = c.fetchone()
109 text_note.insert("1.0", row)
110 con.commit()
111 c.close()
112 # function
113 def update_database():
114 # database connecting
115 con = sqlite3.connect("data.bd")
116 c = con.cursor()
117 # c.execute("INSERT INTO wards (email ,name, passoword , note ) VALUES ('lina@gamil.com','lina','222','hello') ")
118 c.execute("UPDATE wards set note = ? WHERE name = ? AND passoword= ?",
119 [str(text_note.get("1.0", END)), str(e_name.get()), str(e_passward.get())])
120 con.commit()
121 # select the note from inputs
122 # c.execute("SELECT note FROM words WHERE name = ? AND pass = ?",[name, passw])
123
124 # buttons
125 button_save = Button(note_window, text="Save The Text", font=('Times New Roman', 15), bg='lightblue',
126 command=update_database)
127 button_save.place(x=500, y=8)
128
129 note_window.mainloop()
130 except:
131 messagebox.showerror("Error", "Verify user and password")
132 # def save():
133 # # database connecting
134 # con = sqlite3.connect("data.bd")
135 # c = con.cursor()
136 # # input note
137 # inputs = str(text_note.get("1.0", END))
138 # name = str(e_name.get())
139 # passward = str(e_passward.get())
140 # #ScrolledText
141 # entry_note = scrolledtext.ScrolledText(note_window)
142 # entry_note.place(x=10, y=50)
143 # # insert in datebase
144 # # c.execute("INSERT INTO words (name , pass , note ) VALUES('omar', '333', 'what is your old ?') ")
145 # # update note in database
146
147 # inputs = str(text_note.get("1.0", END))
148 # name = str(e_name.get())
149 # passward = str(e_passward.get())
150 # con = sqlite3.connect("data.bd")
151 # c = con.cursor()
152 # c.execute("INSERT INTO wards (email ,name, passoword , note ) VALUES ('lina@gamil.com','lina','222','hello') ")
153 # #c.execute("UPDATE wards set note = ? WHERE name = ? AND passoword = ? ", (inputs,name,passward))
154 # # c.execute("UPDATE wards set note = ? WHERE name = ? AND passoword= ?", [inputs,name,passward])
155 # # c.execute("SELECT note FROM wards WHERE name = ? AND passoword = ?", [name, passward])
156 # # row = c.fetchone()
157 # # print(row)
158 # # con.commit()
159 #
160 # c.execute("UPDATE wards set note = ? WHERE name = ? AND pass= ?", [inputs, name, passward])
161 # c.execute("SELECT note FROM wards WHERE name = ? AND passoword = ?", [name, passward])
162 # row = c.fetchone()
163 # print(row)
164 # con.commit()
165 #
166 # # c.execute("UPDATE hell set note = ? WHERE name = ? AND pass =? ", (inputs, name,passward ))
167 # ##############################################
168 # con = sqlite3.connect("data.bd")
169 # c = con.cursor()
170 # # c.execute("INSERT INTO wards (name , passoword, note ) VALUES ('omar','333','hello warld')")
171 # # c.execute("SELECT note FROM wards WHERE name = 'lina' AND passoword = '111'")
172 # c.execute("SELECT note FROM wards WHERE passoword = ? and name = ?",(passward,name))
173 # row = c.fetchone()
174 # print(row)
175 # # text_note.insert("1.0", row)
176 # con.commit()
177 # ##############################################
178 # #entry name
179 # entry_n = Entry(note_window, width='10')
180 # entry_n.place(x=110, y=20)
181 # #entry passward
182 # entry_p = Entry(note_window, width='10')
183 # entry_p.place(x=10, y=20)
184 # ###########################################
185 # note_window.mainloop()
186
187
188e_name = Entry(window, width='30')
189e_name.place(x=120, y=0)
190e_passward = Entry(window, width='30')
191e_passward.place(x=120, y=20)
192# label
193label_Name = Label(window, text='Name', width='7', bg='lightgreen').place(x=50, y=0)
194label_Passward = Label(window, text='Passward', width='7', bg='lightgreen').place(x=50, y=20)
195
196# buttons
197make_account_button = Button(window, text='Make an account', bg='blue', command=moomar).place(x=150, y=150)
198
199enter_button = Button(window, text='Login', bg='blue', width='12', command=login).place(x=150, y=50)
200# exit
201window.mainloop()
202