-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
194 lines (143 loc) · 7.07 KB
/
app.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
#____________importing required modules_____
from tkinter import *
from tkinter import filedialog,ttk
import tksheet
import sqlite3
import sys
import os
import atexit
from PIL import Image, ImageDraw, ImageTk
import mysql.connector
from mysql.connector import errorcode, errors
#sys.stdout = open("D:\vs_code\PyDBMS main\logs","a")
class Table:
def __init__(self,output_frame):
for i in range(10):
for j in range(10):
self.e=Entry(output_frame,font=('arial 10'),fg='green')
self.e.grid(row=i,column=j)
#______Function to connect to MySQL DB______
def connect():
hostname = hostname_entry_box.get()
username = username_entry_box.get()
password = password_entry_box.get()
dbname = database_name_entry_box.get()
try:
global conn
conn = mysql.connector.connect(
host = "{}".format(hostname),
user = "{}".format(username),
passwd = "{}".format(password),
database = "{}".format(dbname)
)
print("Connection established..")
except mysql.connector.DatabaseError as ez3:
if ez3.errno == 2005:
print("\nNo host present named",'"',hostname,'"',"\nKindly rerun the program")
except mysql.connector.InterfaceError as ez2:
if ez2.errno == 2003:
print("\n>>ERROR: Kindly recheck your connection parameters\n\t\tIf you think parameters are correct, check if mysql service is enabled...\n")
except mysql.connector.ProgrammingError as ez:
if errorcode.ER_ACCESS_DENIED_ERROR == ez.errno:
print("\n>>Access Denied: Kindly recheck your connection parameters..")
#______exit window______
def quit():
top2 = Toplevel(root)
top2.geometry("150x80")
top2.title("Exit")
exit_label = Label(top2,text="Exit?",font = ("Arial",15))
exit_label.place(x=0,y=0)
no = Button(top2,text="cancel",font = ("Arial",13),command = top2.destroy,relief=RAISED).place(relx=0,rely=0.5)
yes = Button(top2,text="ok",font = ("Arial",13),width = 5,command = root.quit,relief=RAISED).place(relx=0.5,rely=0.5)
top2.transient(root)
top2.resizable(False,False)
#___________Creating a window to open a file from desired directory________
def file_dialog_box():
root.filename = filedialog.askopenfilename(initialdir = "/",title="Select A File",filetypes = (("Database file","*.db"),("All Files","*.*")))
#_________Creating a new window similar to root window to create a new file_____________
def newfile_window():
new_window = Toplevel(root)
new_window.geometry("1920x1080")
new_window.title("PyDBMS")
toolbar_frame_new = Frame(new_window,width=1920,height=60,bg="gray22").place(x=0,y=0,anchor="nw")
output_frame_new = Frame(new_window,width=1440,height=1020,bg="gray16").place(x=480,y=60,anchor="nw")
foo_frame_new = Frame(new_window,width=1920,height=30,bg="gray19").place(x=0,y=60,anchor="nw")
querry_frame_new = Frame(new_window,width=480,height=1020,bg="gray20").place(x=0,y=0,anchor="nw")
new_window.option_add('*tearOff', FALSE)
my_menu_new = Menu(toolbar_frame_new,bg="gray30",fg="White",font=("Calibri",12),relief=RAISED)
new_window.config(menu = my_menu_new)
file_menu_new = Menu(my_menu_new)
my_menu_new.add_cascade(label = "FILE",menu = file_menu_new)
file_menu_new.add_command(label = "New",command = newfile_window)
file_menu_new.add_command(label = "Open File",command = file_dialog_box)
file_menu_new.add_command(label = "Save as")
file_menu_new.add_command(label = "Save")
file_menu_new.add_command(label = "Exit",command = quit)
database_menu_new = Menu(my_menu_new)
my_menu_new.add_cascade(label="DATABASE",menu = database_menu_new)
database_menu_new.add_command(label = "Create")
database_menu_new.add_command(label = "Use")
database_menu_new.add_command(label = "Drop")
table_menu_new = Menu(my_menu_new)
my_menu_new.add_cascade(label="TABLE",menu=table_menu_new)
table_menu_new.add_command(label= "Create")
table_menu_new.add_command(label= "Modify")
table_menu_new.add_command(label= "Drop")
#______Defining the root window__________
root = Tk()
root.geometry("1920x1080")
root.title("PyDBMS")
toolbar_frame = Frame(root,width=1920,height=60,bg="gray22").place(x=0,y=0)
output_frame = Frame(root,width=1440,height=990,bg="gray16").place(x=480,y=90)
foo_frame = Frame(root,width=1440,height=30,bg="gray19").place(x=480,y=60)
querry_frame = Frame(root,width=480,height=1020,bg="gray20").place(x=0,y=60)
#______login screen___________
login_window = Toplevel(root)
login_window.title('Login')
login_window.transient(root)
login_window.grab_set()
login_window.geometry("550x250")
login_window.resizable(False,False)
hostname_entry_box = Entry(login_window,width=30,relief=RAISED,font=("Calibre",13))
username_entry_box = Entry(login_window,width=30,relief=RAISED,font=("Calibre",13))
password_entry_box = Entry(login_window,width=30,relief=RAISED,font=("Calibre",13),show = "*")
database_name_entry_box = Entry(login_window,width=30,relief=RAISED,font=("Calibre",13))
hostname_entry_box.place(x=200,y=20,anchor="nw")
username_entry_box.place(x=200,y=60,anchor="nw")
password_entry_box.place(x=200,y=100,anchor="nw")
database_name_entry_box.place(x=200,y=140,anchor="nw")
hostname_entry_label = Label(login_window,text="HOST:",font=("Arial",20)).place(x=10,y=20,anchor="nw")
username_entry_label = Label(login_window,text="USER",font=("Arial",20)).place(x=10,y=60,anchor="nw")
password_entry_label = Label(login_window,text="PASSWORD:",font=("Arial",20)).place(x=10,y=100,anchor="nw")
database_name_entry_label = Label(login_window,text="DATABASE:",font=("Arial",20)).place(x=10,y=140,anchor="nw")
connect_button = Button(login_window,text="Connect",font=("Arial",15),command=lambda:[connect(),login_window.destroy()]).place(x=150,y=200,anchor="nw")
cancel_button = Button(login_window,text="Cancel",font=("Arial",15),command=login_window.destroy).place(x=300,y=200,anchor="nw")
#______Creating a toolbar for root window_________
root.option_add('*tearOff', FALSE)
my_menu = Menu(toolbar_frame,bg="gray30",fg="White",font=("Calibri",12),relief=RAISED)
root.config(menu = my_menu)
file_menu = Menu(my_menu)
my_menu.add_cascade(label = "FILE",menu = file_menu)
file_menu.add_command(label = "New",command=newfile_window)
file_menu.add_command(label = "Open File",command = file_dialog_box)
file_menu.add_command(label = "Save as")
file_menu.add_command(label = "Save")
file_menu.add_command(label = "Exit",command = quit)
database_menu = Menu(my_menu)
my_menu.add_cascade(label="DATABASE",menu = database_menu)
database_menu.add_command(label = "Create")
database_menu.add_command(label = "Use")
database_menu.add_command(label = "Drop")
table_menu = Menu(my_menu)
my_menu.add_cascade(label="TABLE",menu=table_menu)
table_menu.add_command(label= "Create")
table_menu.add_command(label= "Modify")
table_menu.add_command(label= "Drop")
#____main_____
for i in range(10): #Rows
for j in range(10): #Columns
b = Entry(output_frame, text="")
b.grid(row=i, column=j)
root.mainloop()
atexit.register(conn.close)
sys.stdout.close()