def saveAccountInfo(tabControl, tabAcc, accountsWidgets, accountsData, e1, e1text, e2, e2text, messagebox, event=None): dbManager = db.Manage("database.db") birthday_date = "{}/{}/{}".format(accountsData["spinBoxDay_data"].get(), accountsData["spinBoxMonth_data"].get(), accountsData["spinBoxYear_data"].get()) dbManager.connect() dbManager.update( "accounts", """ name='{}', lastname='{}', username='******', password='******', birthday='{}'""".format(accountsWidgets["entry8"].get(), accountsWidgets["entry9"].get(), accountsWidgets["entry10"].get(), accountsWidgets["entry11"].get(), birthday_date), "username='******' and password='******'".format(e1.get(), e2.get())) messagebox.showinfo("Successful", "Account info have been changed successfully") e1text.set(accountsWidgets["entry10"].get()) e2text.set(accountsWidgets["entry11"].get()) tabControl.add(tabAcc, text=e1.get()) cancelEdit(accountsWidgets, accountsData, e1, e2) dbManager.close()
def createTreeView(tab, table, columns): tree = ttk.Treeview(tab, columns=columns) #height=18 scrollb = ttk.Scrollbar(tab, orient="vertical", command=tree.yview) tree.configure(yscrollcommand=scrollb.set) tree['show'] = 'headings' for column in tree["columns"]: if column == "ID": tree.column("{}".format(column), minwidth=500 / len(tree["columns"]), width=750 / len(tree["columns"])) else: tree.column("{}".format(column), minwidth=500 / len(tree["columns"]), width=750 / len(tree["columns"])) for column in tree["columns"]: tree.heading("{}".format(column), text=column) dbManager = db.Manage("database.db") dbManager.connect() for row in dbManager.getTableData(table, "id=id"): tree.insert("", 0, text="", values=(row)) dbManager.close() scrollb.place(x=880, y=10, height=300) tree.place(x=10, y=10, width=880, height=300) return tree
def delete(treeView, table, dashboardData): selected = treeView.focus() ID = treeView.item(selected)["values"][0] print(ID) dbManager = db.Manage("database.db") dbManager.connect() dbManager.delete(table, "id={}".format(ID), debug=True) dbManager.close() treeView.delete(selected) #updateTreeView(treeView,table) widgetsF.updateStats(dashboardData)
def editAccountInfo(data, accountsWidgets, user, passw): labels_data = [ data["l13_data"], data["l14_data"], data["l15_data"], data["l16_data"], data["l17_data"] ] texts = [ "First Name:", "Last Name:", "Username:"******"Password:"******"Birthday:" ] item = 0 for label_data in labels_data: label_data.set(texts[item]) item += 1 accountsWidgets["button6"].place_forget() accountsWidgets["button7"].place(x=600, y=180, width=100, height=40) accountsWidgets["button8"].place(x=500, y=180, width=100, height=40) dbManager = db.Manage("database.db") dbManager.connect() account = dbManager.getTableData( "accounts", "username='******' and password='******'".format(user.get(), passw.get())) dbManager.close() print(data["e10_text"].get()) data["e8_text"].set(account["First Name"]) data["e9_text"].set(account["Last Name"]) data["e10_text"].set(account["Username"]) data["e11_text"].set(account["Password"]) entries = [ accountsWidgets["entry8"], accountsWidgets["entry9"], accountsWidgets["entry10"], accountsWidgets["entry11"] ] ypos = 100 for entry in entries: entry.place(x=275, y=ypos, width=200, height=40) ypos += 40 accountBirthday = str.split(account["Birthday"], "/") data["spinBoxDay_data"].set(accountBirthday[0]) data["spinBoxMonth_data"].set(accountBirthday[1]) data["spinBoxYear_data"].set(accountBirthday[2]) ypos += 25 accountsWidgets["spinBoxDay"].place(x=275, y=ypos, height=30, width=60) accountsWidgets["spinBoxMonth"].place(x=275 + 60, y=ypos, height=30, width=60) accountsWidgets["spinBoxYear"].place(x=275 + 60 + 60, y=ypos, height=30, width=60)
def cancelEdit(accountsWidgets, accountsData, user, passw): #Removing edit widgets cancelEditWidgets = [ accountsWidgets["button7"], accountsWidgets["button8"], accountsWidgets["entry8"], accountsWidgets["entry9"], accountsWidgets["entry10"], accountsWidgets["entry11"], accountsWidgets["button8"], accountsWidgets["spinBoxDay"], accountsWidgets["spinBoxMonth"], accountsWidgets["spinBoxYear"] ] for widget in cancelEditWidgets: widget.place_forget() dbManager = db.Manage("database.db") #Shows account info dbManager.connect() account = dbManager.getTableData( "accounts", "username='******' and password='******'".format(user.get(), passw.get())) dbManager.close() widgetsF.tabAccountWidgets( accountsWidgets, accountsData, account) #LoginSystem().login(account["Username"],account["Password"])
def createAccount(loginWidgets, registerWidgets, registerData, messagebox, event=None): dbManager = db.Manage("database.db") dbManager.connect() dbManager.create_table("accounts", db.accounts_columns) birthday_date = "{}/{}/{}".format(registerData["spinBoxDay_data"].get(), registerData["spinBoxMonth_data"].get(), registerData["spinBoxYear_data"].get()) #Testing #dbManager.insert("accounts",accounts_columnsList,values) if registerWidgets["entry3"].get() and registerWidgets["entry4"].get( ) and registerWidgets["entry5"].get() and registerWidgets["entry6"].get( ) and birthday_date: if not hasNumbers(registerWidgets["entry3"].get()) and not hasNumbers( registerWidgets["entry4"].get()): try: values = registerWidgets["entry3"].get(), registerWidgets[ "entry4"].get(), registerWidgets["entry5"].get( ), registerWidgets["entry6"].get(), birthday_date dbManager.insert("accounts", db.accounts_columnsList, values) registerWidgets["label11"].place_forget() messagebox.showinfo("Successful!", "You have successfully signed up!") widgetsF.showLogin(registerWidgets, loginWidgets) except: registerData["errorMessage"].set("Username is already taken!") registerWidgets["label11"].place(x=270, y=400) raise else: registerData["errorMessage"].set( "First Name/Last Name can't contain numbers!") registerWidgets["label11"].place(x=150, y=400) else: registerData["errorMessage"].set("Please complete all the fields!") registerWidgets["label11"].place(x=260, y=400) dbManager.close()
def updateStats(data): dbManager = db.Manage("database.db") dbManager.connect() students = dbManager.getTableData("Students","id=id") classes = dbManager.getTableData("Classes","id=id") employees = dbManager.getTableData("employees","id=id") classTypes = dbManager.getTableData("ClassTypes","id=id") dbManager.close() incomeCalc = 0 for class_ in classes: try: incomeCalc += int(class_[6]) except: print("{} isn't integer/float".format(class_[6])) outcomeCalc = 0 for employee in employees: try: outcomeCalc += int(employee[8]) except: print("{} isn't integer/float".format(employee[8])) data["studentsStats"].set("Students: {}".format(len(students))) data["classesStats"].set("Classes: {}".format(len(classes))) data["employeesStats"].set("Employees: {}".format(len(employees))) data["classTypesStats"].set("Class Types: {}".format(len(classTypes))) data["income"].set("Income: +{}$".format(incomeCalc)) data["outcome"].set("Outcome: -{}$".format(outcomeCalc)) data["profit"].set("Profit: {}$".format(incomeCalc - outcomeCalc))
# get screen width and height ws = root.winfo_screenwidth() # width of the screen hs = root.winfo_screenheight() # height of the screen # calculate x and y coordinates for the Tk root window x = (ws / 2) - (w / 2) y = (hs / 2) - (h / 2) # set the dimensions of the screen # and where it is placed root.geometry('%dx%d+%d+%d' % (w, h, x, y)) s = ttk.Style() dbManager = db.Manage("database.db") createTop = topL.Create() entriesList = [] tabControl = ttk.Notebook(root) tabDashboard = ttk.Frame(tabControl) tabStaff = ttk.Frame(tabControl) tabClassTypes = ttk.Frame(tabControl) tabClasses = ttk.Frame(tabControl) tabStudents = ttk.Frame(tabControl) tabAccount = ttk.Frame(tabControl) tabs = { "tabDashboard": tabDashboard, "tabStaff": tabStaff,