Library
Library
class library:
def __init__(self, root):
self.root = root
self.root.title("Neel Games Store")
self.root.geometry("1550x840+0+0")
self.root.state("zoomed")
self.root.resizable(0, 0)
self.main()
@staticmethod
def connect_to_db():
return mysql.connector.connect(
host="localhost",
user="root",
password="Neel_123",
database="mydata"
)
def fetch_library_items(self):
db = self.connect_to_db()
cursor = db.cursor()
try:
cursor.execute("SELECT id, game_name, price FROM cart_item") # Fetch
'id' to identify each game uniquely
items = cursor.fetchall()
return items
except Exception as e:
messagebox.showerror("Error", f"Failed to fetch library items:
{str(e)}")
return []
finally:
cursor.close()
db.close()
def refresh_library(self):
for widget in self.root.winfo_children():
widget.destroy()
self.main()
def main(self):
main_frame = Frame(self.root, width=300, height=840, bg="#1C1C1C")
main_frame.place(x=0, y=0)
items = self.fetch_library_items()
y_position = 120
if items:
for item in items:
game_id = item[0]
game_name = item[1]
game_price = item[2]
y_position += 50
else:
Label(right_Frame, text="No games in your library yet.",
font=("cursive", 20, "bold"), bg="#333333", fg="white").place(x=50, y=y_position)
def backHome(self):
for widget in self.root.winfo_children():
widget.destroy()
def open_browser(self):
browser(self.root)
if __name__ == "__main__":
root = Tk()
obj = library(root)
root.mainloop()