aboutsummaryrefslogtreecommitdiff
path: root/main.py
diff options
context:
space:
mode:
Diffstat (limited to 'main.py')
-rw-r--r--main.py80
1 files changed, 80 insertions, 0 deletions
diff --git a/main.py b/main.py
new file mode 100644
index 0000000..261a9fe
--- /dev/null
+++ b/main.py
@@ -0,0 +1,80 @@
+#!/bin/python3
+
+from frames import *
+from getpass import getuser
+import mariadb
+#import pdb
+
+
+fields = (('userid', 'varchar(100)', 'PRIMARY KEY'),
+ ('ptype', 'varchar(4)', 'NOT NULL'))
+
+
+def start():
+ with mariadb.connect(host="localhost", user=getuser(), password='') as connection:
+ with connection.cursor() as cursor:
+
+ # check if databse exist
+ cursor.execute('SHOW DATABASES')
+ for dbs in cursor.fetchall():
+ if 'ptest' in dbs:
+ break
+ else:
+ print('Creating database ptest.')
+ cursor.execute("CREATE DATABASE ptest")
+ cursor.execute("USE ptest")
+
+ # check if table exist and is in proper format
+ cursor.execute('SHOW TABLES')
+ for tables in cursor.fetchall():
+ if 'records' in tables:
+ cursor.execute("DESCRIBE records")
+ columns = cursor.fetchall()
+ l_fields = len(fields)
+ l_columns = len(columns)
+
+ table_ok = True
+ if l_fields != l_columns:
+ table_ok = False
+ for i in range(l_fields):
+ if fields[i][0] != columns[i][0] or fields[i][1] != columns[i][1]:
+ table_ok = False
+
+ if table_ok == False:
+ cursor.execute("DROP TABLE records")
+ continue
+ break
+ else:
+ print('Creating table records.')
+ columns = ''
+ for i in range(len(fields)):
+ if i == 0:
+ columns += ' '.join(fields[i])
+ else:
+ columns += ', ' + ' '.join(fields[i])
+ cursor.execute("CREATE TABLE records({})".format(columns))
+
+ root = Tk()
+ root.title("Personality Test")
+
+ WIN_HEIGHT, WIN_WIDTH = 1200, 675
+ root.geometry(f"{WIN_HEIGHT}x{WIN_WIDTH}")
+ #root.minsize(WIN_HEIGHT, WIN_WIDTH)
+ #root.resizable(width=False, height=False)
+ root.configure(background="black")
+ root.bind_all("<Button-1>", lambda event: event.widget.focus_set())
+
+ #startpage = RecordsPage(HomePage(root, cursor), root, cursor)
+ startpage = HomePage(root, cursor)
+ startpage.pack(fill=BOTH, expand=TRUE)
+ startpage.mainloop()
+
+ connection.commit()
+
+
+start()
+
+# try:
+# except Error as e:
+# messagebox.showerror(title='Oops!', message=e)
+#