-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
239 lines (217 loc) · 9.24 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#!/usr/bin/python3
# Black DataBase v1.2
# Data Base Connector
import os
import platform
import sys
import webbrowser
from datetime import datetime
try:
from tkinter import *
from tkinter.colorchooser import askcolor
from tkinter.ttk import *
from tkinter.messagebox import *
except ImportError:
os.system("pip install tk-tools")
try:
import mysql.connector
except ImportError:
os.system("pip install mysql-connector-python")
try:
from win10toast import ToastNotifier
except ImportError:
os.system("pip install win10toast")
class black_database(object):
def __init__(self):
super(black_database,self).__init__()
def main_window(self):
global root
root = Tk()
root.title('Black-DataBase')
self.photo = PhotoImage(file = 'black.png')
self.database_help = """
help
exit or quit
INSERT INTO customers (name, address) VALUES (n,n)
show database
DELETE FROM customers WHERE address = n
"""
global Host,Password,Database,user
menu = Menu(root)
aboutmenu = Menu(menu,tearoff=0)
aboutmenu.add_command(label='Help',accelerator="F1",command=self.black_help)
aboutmenu.add_command(label='Black',accelerator="F2",command=self.black)
thememenu = Menu(root,tearoff=0)
thememenu.add_command(label='Dark',command=self.dark)
thememenu.add_command(label='Light',command=self.light)
thememenu.add_command(label='Custom',command=self.custom)
donate_file = Menu(menu,tearoff=0)
donate_file.add_command(label='donate',accelerator="F5",command=self.donate)
menu.add_cascade(label='About',menu=aboutmenu)
menu.add_cascade(label='Theme',menu=thememenu)
menu.add_cascade(label='Donate',menu=donate_file)
global txt
root.config(menu=menu)
txt = Text(root,width=20,height=30)
txt.pack()
txt.place(bordermode=INSIDE,x=10,y=1)
self.user_label = Label(root,text='Enter User:')
self.user_label.pack()
self.user = Entry(root)
self.user.pack()
self.user.focus()
self.host_label = Label(root,text='Enter Host:',background='white')
self.host_label.pack()
self.Host = Entry(root)
self.Host.pack()
self.pass_label = Label(root,text='Enter Password:',background='white')
self.pass_label.pack()
self.Password = Entry(root,show="*")
self.Password.pack()
self.pass_label_2 = Label(root,text='Retype Password',background='white')
self.pass_label_2.pack()
self.Password_re = Entry(root,show="*")
self.Password_re.pack()
self.database_label = Label(root,text='Enter Database:')
self.database_label.pack()
self.Database = Entry(root)
self.Database.pack()
global login,exit
login = Button(root,text='Login',command=lambda: self.login_database())
login.pack()
login.place(x=215,y=210)
exit = Button(root,text='Exit',command=lambda: self.ext())
exit.pack()
exit.place(x=215,y=240)
root.bind("<F1>",lambda x: self.black_2(x))
root.bind("<F2>",lambda x: self.black_help_2(x))
root.bind("<F5>",lambda x: self.donate_2(x))
root.iconphoto(False,self.photo)
root.resizable(0,0)
root.attributes('-alpha',0.9)
root.configure(background='white')
root.geometry("500x300")
root.mainloop()
def ext(self):
root.destroy()
root.quit()
def login_database(self):
x = []
global dbs,user_lbl
try:
if self.Database.get() == '' or self.Database.get() == ' ':
x.append(1)
elif self.Password.get() == '' or self.Password.get() == ' ':
x.append(2)
elif self.Password.get() == self.Password_re.get():
print(True)
elif self.Host == '' or self.Host == ' ':
x.append(3)
elif self.user == '' or self.user == ' ':
x.append(4)
else:
user_lbl = Label(root,text=self.user.get(),background='white',foreground='black')
user_lbl.pack(side=BOTTOM)
txt.insert(END,f"Connecting User: {self.user.get()}")
database = mysql.connector.connect(user=self.user.get(),password=self.Password.get(),host=self.Host.get(),database=self.Database.get(),)
print(database)
try:
dbs = database.cursor()
txt.insert(END,f"\nUser: {self.user.get()} Connected!")
toast = ToastNotifier() # Black Data Base Icon
toast.show_toast('Black DataBase',f'Data Base: {self.Database.get()}',icon_path="None",duration=5)
self.database_command()
except:
self.main_window()
finally:
pass
if x:
showerror(title='Cannot Connecting',message='Please, Check user-password-host-DataBase')
except mysql.connector.errors.InterfaceError:
toaster = ToastNotifier() # Black Data Base Icon
toaster.show_toast('Black DataBase',f'Data Base: {self.Database.get()}')
txt.insert(END,f"Cannot Connecting To {self.user.get()}")
showerror(title='MySql Error',message='Cannot Connecting To Database')
root.destroy()
self.main_window()
finally:
print()
def donate(self):
webbrowser.open_new_tab('https://idpay.ir/mrprogrammer2938')
def donate_2(self,x):
webbrowser.open_new_tab('https://idpay.ir/mrprogrammer2938')
def database_command(self):
time_zone = datetime.time()
try:
while True:
command = input(f"{self.user}/Command/> ").split()
if command == []:
pass
elif command.lower() == 'help':
print(self.database_help)
elif command.lower() == 'exit' or command.lower() == 'quit':
print("Stop...\n")
self.user.delete(0,END)
self.Database.delete(0,END)
self.Password.delete(0,END)
self.Host.delete(0,END)
print(f"Exiting User On: {time_zone}")
else:
dbs.execute(command)
dbs.commit()
except (KeyboardInterrupt,EOFError,Exception):
print("Stop...\n")
self.user.delete(0,END)
self.Database.delete(0,END)
self.Password.delete(0,END)
self.Host.delete(0,END)
print(f"Exiting User On: {time_zone}")
sys.exit()
def black(self):
webbrowser.open_new_tab('https://github.com/black-software-Com')
def black_2(self,x):
webbrowser.open_new_tab('https://github.com/black-software-Com')
def black_help(self):
webbrowser.open_new_tab('')
def black_help_1(self,x):
webbrowser.open_new_tab('')
def dark(self):
root.config(background='black')
self.database_label.config(background='black',foreground='green')
self.host_label.config(background='black',foreground='green')
self.pass_label.config(background='black',foreground='green')
self.pass_label_2.config(background='black',foreground='green')
self.user_label.config(background='black',foreground='green')
user_lbl.config(background='black',foreground='green')
def light(self):
root.config(background='white')
self.database_label.config(background='white',foreground='black')
self.host_label.config(background='white',foreground='black')
self.pass_label.config(background='white',foreground='black')
self.pass_label_2.config(background='white',foreground='black')
self.user_label.config(background='white',foreground='black')
user_lbl.config(background='white',foreground='black')
def custom(self):
try:
choosecolor = askcolor(title='Choose Color')
root.config(background=choosecolor[1])
self.database_label.config(background='white',foreground='black')
self.host_label.config(background='white',foreground='black')
self.pass_label.config(background='white',foreground='black')
self.pass_label_2.config(background='white',foreground='black')
self.user_label.config(background='white',foreground='black')
except TclError:
print("Please, Choose Color!\n")
@staticmethod
def title():
if platform.system() == 'Linux':
os.system(f"printf '\033]2;Black-DataBase'")
else:
os.system("title Black-DataBase")
if __name__ == '__main__':
time_zone = datetime.now()
window = black_database()
window.title()
print(f"\nStart Black-DataBase At: {time_zone}")
window.main_window()
print(f"Close Black-DataBase At: {time_zone}")