0% found this document useful (0 votes)
8 views4 pages

Neel Games Store Application

contains home file

Uploaded by

kneelgames
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views4 pages

Neel Games Store Application

contains home file

Uploaded by

kneelgames
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

from tkinter import *

from PIL import Image, ImageTk


import [Link]
from tkinter import messagebox
from browse import browser
from feedbox import Feedback
from login import login_page
from library import library

cart = []

class videogame:
def __init__(self, root):
[Link] = root
[Link]("Neel Games Store")
[Link]("1550x840+0+0")
[Link]("zoomed")
[Link](0, 0)
[Link]()

@staticmethod
def connect_to_db():
return [Link](
host="localhost",
user="root",
password="Neel_123",
database="mydata"
)

def add_to_cart(self, game_name, game_price):


[Link]({'name': game_name, 'price': game_price})
[Link]("Cart", f"Added {game_name} to the cart!")

def place_order(self):
db = self.connect_to_db()
cursor = [Link]()

try:
for item in cart:
[Link](
"INSERT INTO cart_item (game_name, price) VALUES (%s, %s)",
(item['name'], item['price'])
)
[Link]()
[Link]("Order", "Order placed successfully!")
[Link]() # Clear the cart after placing the order
except Exception as e:
[Link]()
[Link]("Error", f"Failed to place order: {str(e)}")
finally:
[Link]()
[Link]()

def remove_from_cart(self, game_name):


global cart
# Find the item in the cart and remove it
cart = [item for item in cart if item['name'] != game_name]
# Refresh the cart view to update the UI
self.view_cart()

def view_cart(self):
cartFrame = Frame([Link], width=1230, height=840, bg="#333333")
[Link](x=300, y=0)

Label(cartFrame, text="Your Cart", font=("cursive", 30, "bold"),


bg="#333333", fg="white").place(x=500, y=40)

y_position = 120
total = 0

for item in cart:


Label(cartFrame, text=item['name'], font=("cursive", 20, "bold"),
bg="#333333", fg="white").place(x=50, y=y_position)
Label(cartFrame, text=f"₹{item['price']}", font=("cursive", 20,
"bold"), bg="#333333", fg="white").place(x=400, y=y_position)

# Adjust the y position for the Remove button


remove_btn = Button(cartFrame, text="Remove", command=lambda
g=item['name']: self.remove_from_cart(g), font=("cursive", 10, "bold"), width=10,
bg="red", bd=0, fg="white", cursor="hand2", activebackground="red",
activeforeground="white")
remove_btn.place(x=600, y=y_position)

y_position += 50
total += item["price"]

Label(cartFrame, text=f"Total:₹{total}", font=("cursive", 25, "bold"),


bg="#333333", fg="white").place(x=50, y=y_position)

backButton = Button(cartFrame, text="<", command=[Link],


font=("cursive", 20, "bold"), width=1, bg="#333333", bd=0, fg="white",
activebackground="#333333", activeforeground="white", cursor="hand2")
[Link](x=1, y=1)

placeOrderButton = Button(cartFrame, command=self.place_order, text="Place


Order", font=("cursive", 20, "bold"), width=15, bg="black", bd=0, fg="gold",
cursor="hand2")
[Link](x=50, y=y_position + 40)

def main(self):
main_frame = Frame([Link], width=300, height=840, bg="#1C1C1C")
main_frame.place(x=0, y=0)

browse = Button(main_frame, command=self.open_browser, text="Browse",


font=("cursive", 20, "bold"), width=10, bg="#1C1C1C", bd=0, fg="light gray",
cursor="hand2")
[Link](x=50, y=50)

lbry_btn = Button(main_frame,command=self.open_library, text="Library",


font=("cursive", 20, "bold"), width=10, bg="#1C1C1C", bd=0, fg="light gray",
cursor="hand2")
lbry_btn.place(x=50, y=150)

feedback_btn = Button(main_frame, command=self.open_feedback,


text="FeedBack", font=("cursive", 20, "bold"), width=10, bg="#1C1C1C", bd=0,
fg="light gray", cursor="hand2")
feedback_btn.place(x=50, y=250)

report_btn = Button(main_frame, text="Report", font=("cursive", 20,


"bold"), width=10, bg="#1C1C1C", bd=0, fg="light gray", cursor="hand2")
report_btn.place(x=50, y=350)

cart_btn = Button(main_frame, text="Cart", command=self.view_cart,


font=("cursive", 20, "bold"), width=10, bg="#1C1C1C", bd=0, fg="light gray",
cursor="hand2")
cart_btn.place(x=50, y=450)

# Update the login/logout button text based on login status


login_btn_text = "Log Out"
self.login_btn = Button(main_frame, text=login_btn_text, font=("cursive",
20, "bold"), width=10, bg="#1C1C1C", bd=0, fg="light gray", cursor="hand2")
self.login_btn.place(x=50, y=770)

right_Frame = Frame([Link], width=1230, height=840, bg="#333333")


right_Frame.place(x=300, y=0)

title_lbl = Label(right_Frame, text="Welcome to The Video Game Store",


font=("helvatica", 20, "bold"), bg="#333333", fg="white")
title_lbl.place(x=50, y=50)

self.contect_frame = Frame(right_Frame, width=1130, height=540, bg="black")


self.contect_frame.place(x=50, y=120)

lblGameName = Label(self.contect_frame, text="Best Seller Games",


font=("helvatica", 20, "bold"), bg="black", fg="white")
[Link](x=50, y=50)

games = [
{"name": "Resident Evil 8", "price": 2399, "image": "C:/Users/NEEL
PATEL/OneDrive/Desktop/project images/story_game_img6.jpg", "x": 50, "y": 130},
{"name": "A Plague Tale: Requiem", "price": 2299, "image":
"C:/Users/NEEL PATEL/OneDrive/Desktop/project images/story_game_img2.jpg", "x":
410, "y": 130},
{"name": "Red Dead Redemption 2", "price": 3199, "image":
"C:/Users/NEEL PATEL/OneDrive/Desktop/project images/rpg_game_img4.jpg", "x": 780,
"y":130}
]

for game in games:


image = [Link](game["image"])
image = [Link]((250, 300), [Link])
photoimage = [Link](image)

lblGame = Label(self.contect_frame, image=photoimage, bd=4)


[Link] = photoimage
[Link](x=game["x"], y=game["y"])

game1Text = Label(self.contect_frame, text=game["name"],


font=("cursive", 20, "bold"), bg="black", fg="white")
[Link](x=game["x"], y=game["y"] + 310)

btnAddToCart = Button(self.contect_frame, command=lambda g=game:


self.add_to_cart(g["name"], g["price"]), text="Add To Cart", font=("cursive", 10,
"bold"), width=10, bg="black", bd=0, fg="white", cursor="hand2",
activebackground="black", activeforeground="white")
[Link](x=game["x"], y=game["y"] + 350)

btnPriceGame = Label(self.contect_frame, text=f"₹{game['price']}",


font=("cursive", 15, "bold"), bg="black", fg="white")
[Link](x=game["x"] + 90, y=game["y"] + 350)

def open_browser(self):
browser([Link])

def open_feedback(self):
Feedback([Link])

def open_login(self):
login_page([Link])

def open_library(self):
library([Link])

if __name__ == "__main__":
root = Tk()
obj = videogame(root)
[Link]()

Common questions

Powered by AI

The application uses a class-based structure, specifically within the 'videogame' class, to initialize and manage different windows. It defines separate methods such as 'open_browser', 'open_feedback', 'open_login', and 'open_library', each designed to initialize different parts of the application interface by instantiating other modules or classes. This modular design structure helps in organizing the code and facilitates easy navigation and interaction across different functionalities of the application .

The application's design employs a modular approach by using separate methods within the 'videogame' class to handle different windows and functionalities, which supports scalability. Adding new functionalities like 'Account Management' or 'Wishlist' can be achieved by creating additional methods or integrating new modules into this existing framework. However, as the code relies heavily on global variables and lacks a cohesive database schema or business logic separation, significant refactoring may be necessary to ensure consistency and maintain performance as functionalities grow .

In the application, lambda functions are used in button components to create small anonymous functions at runtime. This is particularly significant for associating buttons with specific data-driven actions, such as passing game-specific arguments to functions like "remove_from_cart" or "add_to_cart" without creating separate named functions. This pattern helps keep the code concise and maintains the clean association between the visual interface and functionality, allowing dynamic data to be passed seamlessly through button interactions .

The 'main' method serves as the central entry point for initializing the videogame application interface. It creates the primary navigation layout by placing buttons on the 'main_frame' for navigating to different sections of the application like 'Browse', 'Library', 'Feedback', etc. It enables the initial configuration of the window and sets the stage for user navigation, allowing users to switch between views directly from the main menu. This method helps maintain order and user-friendly interaction throughout the application use .

The application employs a function 'connect_to_db' to establish a connection to the MySQL database. During transactions such as placing an order, it wraps database operations within a try-except block inside the 'place_order' method to handle any exceptions that may occur. If an error is encountered, it rolls back the transaction, and upon success, the transaction is committed. Finally, whether successful or not, the database cursor and connection are closed in the 'finally' block to ensure resources are properly managed .

The application does not explicitly implement any mechanism to prevent duplicate entries in the shopping cart. Each time a user adds a game to the cart, it appends the game to the 'cart' list without checking if the game already exists within the list. Therefore, it allows duplicate entries, as there is no logic to validate or enforce unique entries within the 'add_to_cart' method .

The visual layout of the shopping cart is structured using a 'Frame' widget that covers a portion of the main window. It contains labels for displaying each game's name and price located within fixed positions, data-driven by the items in the 'cart'. Buttons for removing items are dynamically placed next to each game's entry. It includes a label titled 'Your Cart' and displays the total price of the items. Additionally, there are buttons for navigating back to the main view and for placing an order. The placement and design elements are facilitated by specific coordinates and style settings in cursive/fonts and colors .

The application adds a game to the shopping cart by appending a dictionary containing the game's name and price to the global "cart" list. When a game is added, it displays an informational message to the user confirming the addition. The function that handles this is "add_to_cart", which takes "game_name" and "game_price" as parameters .

The application employs a basic error-handling strategy using Python's try-except-finally construct during the 'place_order' transaction. It attempts to execute database operations within a 'try' block and catches exceptions using the 'except' block, where it performs a rollback on the database transaction to undo partial changes. A message box displays an error message if the operation fails. Regardless of success or failure, the 'finally' block ensures that the database cursor and connection are closed, preventing resource leaks .

The application determines which image to display for each video game by using the 'games' list, where each element is a dictionary containing the keys 'name', 'price', and 'image', with the image path specified as its value. The image for each game is loaded using the PIL library to open and resize the image file. A 'Label' widget is used to display each resized image alongside the corresponding game name and price, positioned at the specified coordinates [

You might also like