From 0b6083b0b6b1312a5ca024bd90a2dc060afc5e75 Mon Sep 17 00:00:00 2001 From: kanchanrai7 <114416916+kanchanrai7@users.noreply.github.com> Date: Sun, 1 Oct 2023 23:14:41 +0530 Subject: [PATCH 1/3] Add: Type Racer Game --- projects/Type Racer Game/Typer_racer.py | 180 ++++++++++++++++++++++++ 1 file changed, 180 insertions(+) create mode 100644 projects/Type Racer Game/Typer_racer.py diff --git a/projects/Type Racer Game/Typer_racer.py b/projects/Type Racer Game/Typer_racer.py new file mode 100644 index 000000000..c9c7d64b1 --- /dev/null +++ b/projects/Type Racer Game/Typer_racer.py @@ -0,0 +1,180 @@ +import tkinter as tk +from tkinter import ttk +import random +import time + +# List of random English sentences for the game +sentences = [ + "The quick brown fox jumps over the lazy dog", + "Python is an interpreted high-level programming language", + "I'm learning to code with Python and it's fun", + "A journey of a thousand miles begins with a single step", + "Coding is not just about algorithms, it's about logic", + "Practice makes perfect in programming", + "Innovation distinguishes between a leader and a follower", + "The only way to do great work is to love what you do", + "Coding is the language of the future", + "Keep calm and code on", +] + +# Initialize the game +score = 0 +start_time = 0 +current_sentence = random.choice(sentences) +timer_duration = 30 # Countdown timer duration in seconds +countdown_duration = 5 # Countdown timer duration in seconds + +# Flag to indicate whether the game has started +game_started = False + +# Function to start the game with a countdown +def start_game(): + global start_time, current_sentence, timer_duration, score, game_started + score = 0 + timer_duration = 30 # Reset the timer duration to 30 seconds + countdown_label.config(text="Get ready!") + root.update() + time.sleep(1) + for i in range(countdown_duration, 0, -1): # Use countdown duration + countdown_label.config(text=str(i)) + root.update() + time.sleep(1) + countdown_label.config(text="Go!") + root.update() + time.sleep(1) + countdown_label.config(text="") + root.update() + start_time = time.time() + current_sentence = random.choice(sentences) # Select a new random sentence + sentence_label.config(text=current_sentence) + input_box.delete(0, tk.END) + input_box.focus() + input_box.config(foreground='black', width=40) # Reset text color and increase width + game_started = True # Set the game started flag + start_main_timer() # Start the main game timer after the countdown + +# Function to reset the game +def reset_game(): + global game_started + game_started = False + countdown_label.config(text="") + submit_score() # Submit the score to reset the progress bar + +# Function to start the main game timer +def start_main_timer(): + global timer_duration, game_started + if timer_duration > 0 and game_started: + timer_label.config(text=f"Time left: {timer_duration} seconds") + countdown_label.config(text=str(timer_duration)) # Update countdown_label here + timer_duration -= 1 + root.after(1000, start_main_timer) + elif game_started: + timer_label.config(text="Time's up!") + submit_score() + +# Function to handle typing and change text color +def check_input(event): + input_text = input_box.get() + if current_sentence.startswith(input_text): + input_box.config(foreground='green') # Correct text color + update_progress_bar(len(input_text)) + else: + input_box.config(foreground='red') # Incorrect text color + +# Function to handle submission of score +def submit_score(): + global current_sentence, game_started + end_time = time.time() + time_taken = round(end_time - start_time, 2) + if input_box.get() == current_sentence: + wpm = calculate_wpm(time_taken, len(current_sentence.split())) + result_label.config(text=f"Correct! Time taken: {time_taken} seconds, WPM: {wpm}", foreground='green') + reset_progress_bar() + animate_result_label() + current_sentence = random.choice(sentences) # Select a new random sentence + start_game() + else: + result_label.config(text=f"Incorrect. Time taken: {time_taken} seconds", foreground='red') + animate_result_label() + +# Function to animate the result label +def animate_result_label(): + result_label.config(foreground='red') + root.after(100, lambda: result_label.config(foreground='black')) + root.after(200, lambda: result_label.config(foreground='red')) + root.after(300, lambda: result_label.config(foreground='black')) + root.after(400, lambda: result_label.config(foreground='red')) + root.after(500, lambda: result_label.config(foreground='black')) + root.after(600, lambda: result_label.config(foreground='red')) + root.after(700, lambda: result_label.config(foreground='black')) + root.after(800, lambda: result_label.config(foreground='red')) + root.after(900, lambda: result_label.config(foreground='black')) + root.after(1000, lambda: result_label.config(foreground='red')) + root.after(1100, lambda: result_label.config(text="", foreground='black')) + +# Function to update the progress bar +def update_progress_bar(length): + progress = min(length / len(current_sentence), 1.0) * 100 + progressbar_label.config(text=f"Progress: {int(progress)}%") + progressbar['value'] = progress + +# Function to reset the progress bar +def reset_progress_bar(): + progressbar_label.config(text="Progress: 0%") + progressbar['value'] = 0 + +# Countdown timer function +def countdown(): + global timer_duration, game_started + if timer_duration > 0 and game_started: + timer_label.config(text=f"Time left: {timer_duration} seconds") + countdown_label.config(text=str(timer_duration)) # Update countdown_label here + timer_duration -= 1 + root.after(1000, countdown) + +# Function to calculate WPM +def calculate_wpm(time_taken, word_count): + minutes = time_taken / 60 + wpm = (word_count / 5) / minutes + return round(wpm) + +# Initialize the GUI +root = tk.Tk() +root.geometry("800x400") +root.title("TypeRacer") + + +# Create the widgets with ttk themes +style = ttk.Style() +style.configure("TLabel", foreground="black", font=("Arial", 14)) +style.configure("TButton", font=("Arial", 16)) + +sentence_label = ttk.Label(root, text=current_sentence, wraplength=700, justify='left') +input_box = ttk.Entry(root, font=("Arial", 16), width=40) # Increase width +submit_button = ttk.Button(root, text="Submit", command=submit_score) +reset_button = ttk.Button(root, text="Reset", command=reset_game) +result_label = ttk.Label(root) +progressbar_label = ttk.Label(root, text="Progress: 0%") +progressbar = ttk.Progressbar(root, orient=tk.HORIZONTAL, length=200, mode="determinate") +timer_label = ttk.Label(root, text=f"Time left: {timer_duration} seconds") +countdown_label = ttk.Label(root, font=("Arial", 24), foreground="red") + +# Add the widgets to the GUI +sentence_label.pack(pady=20) +input_box.pack(pady=10) +submit_button.pack(side=tk.RIGHT, padx=10) +reset_button.pack(side=tk.RIGHT, padx=10) +result_label.pack(pady=10) +progressbar_label.pack(pady=10) +progressbar.pack(pady=10) +timer_label.pack(pady=10) +countdown_label.pack(pady=10) + +# Bind the typing event to the input_box +input_box.bind("", check_input) + +# Start the game +start_game() + +# Start the GUI event loop +root.mainloop() From 693f04d460522b7a66237afe99bbff64abd26311 Mon Sep 17 00:00:00 2001 From: kanchanrai7 <114416916+kanchanrai7@users.noreply.github.com> Date: Sun, 1 Oct 2023 23:20:12 +0530 Subject: [PATCH 2/3] Delted pls ignore --- projects/Type Racer Game/Typer_racer.py | 180 ------------------------ 1 file changed, 180 deletions(-) delete mode 100644 projects/Type Racer Game/Typer_racer.py diff --git a/projects/Type Racer Game/Typer_racer.py b/projects/Type Racer Game/Typer_racer.py deleted file mode 100644 index c9c7d64b1..000000000 --- a/projects/Type Racer Game/Typer_racer.py +++ /dev/null @@ -1,180 +0,0 @@ -import tkinter as tk -from tkinter import ttk -import random -import time - -# List of random English sentences for the game -sentences = [ - "The quick brown fox jumps over the lazy dog", - "Python is an interpreted high-level programming language", - "I'm learning to code with Python and it's fun", - "A journey of a thousand miles begins with a single step", - "Coding is not just about algorithms, it's about logic", - "Practice makes perfect in programming", - "Innovation distinguishes between a leader and a follower", - "The only way to do great work is to love what you do", - "Coding is the language of the future", - "Keep calm and code on", -] - -# Initialize the game -score = 0 -start_time = 0 -current_sentence = random.choice(sentences) -timer_duration = 30 # Countdown timer duration in seconds -countdown_duration = 5 # Countdown timer duration in seconds - -# Flag to indicate whether the game has started -game_started = False - -# Function to start the game with a countdown -def start_game(): - global start_time, current_sentence, timer_duration, score, game_started - score = 0 - timer_duration = 30 # Reset the timer duration to 30 seconds - countdown_label.config(text="Get ready!") - root.update() - time.sleep(1) - for i in range(countdown_duration, 0, -1): # Use countdown duration - countdown_label.config(text=str(i)) - root.update() - time.sleep(1) - countdown_label.config(text="Go!") - root.update() - time.sleep(1) - countdown_label.config(text="") - root.update() - start_time = time.time() - current_sentence = random.choice(sentences) # Select a new random sentence - sentence_label.config(text=current_sentence) - input_box.delete(0, tk.END) - input_box.focus() - input_box.config(foreground='black', width=40) # Reset text color and increase width - game_started = True # Set the game started flag - start_main_timer() # Start the main game timer after the countdown - -# Function to reset the game -def reset_game(): - global game_started - game_started = False - countdown_label.config(text="") - submit_score() # Submit the score to reset the progress bar - -# Function to start the main game timer -def start_main_timer(): - global timer_duration, game_started - if timer_duration > 0 and game_started: - timer_label.config(text=f"Time left: {timer_duration} seconds") - countdown_label.config(text=str(timer_duration)) # Update countdown_label here - timer_duration -= 1 - root.after(1000, start_main_timer) - elif game_started: - timer_label.config(text="Time's up!") - submit_score() - -# Function to handle typing and change text color -def check_input(event): - input_text = input_box.get() - if current_sentence.startswith(input_text): - input_box.config(foreground='green') # Correct text color - update_progress_bar(len(input_text)) - else: - input_box.config(foreground='red') # Incorrect text color - -# Function to handle submission of score -def submit_score(): - global current_sentence, game_started - end_time = time.time() - time_taken = round(end_time - start_time, 2) - if input_box.get() == current_sentence: - wpm = calculate_wpm(time_taken, len(current_sentence.split())) - result_label.config(text=f"Correct! Time taken: {time_taken} seconds, WPM: {wpm}", foreground='green') - reset_progress_bar() - animate_result_label() - current_sentence = random.choice(sentences) # Select a new random sentence - start_game() - else: - result_label.config(text=f"Incorrect. Time taken: {time_taken} seconds", foreground='red') - animate_result_label() - -# Function to animate the result label -def animate_result_label(): - result_label.config(foreground='red') - root.after(100, lambda: result_label.config(foreground='black')) - root.after(200, lambda: result_label.config(foreground='red')) - root.after(300, lambda: result_label.config(foreground='black')) - root.after(400, lambda: result_label.config(foreground='red')) - root.after(500, lambda: result_label.config(foreground='black')) - root.after(600, lambda: result_label.config(foreground='red')) - root.after(700, lambda: result_label.config(foreground='black')) - root.after(800, lambda: result_label.config(foreground='red')) - root.after(900, lambda: result_label.config(foreground='black')) - root.after(1000, lambda: result_label.config(foreground='red')) - root.after(1100, lambda: result_label.config(text="", foreground='black')) - -# Function to update the progress bar -def update_progress_bar(length): - progress = min(length / len(current_sentence), 1.0) * 100 - progressbar_label.config(text=f"Progress: {int(progress)}%") - progressbar['value'] = progress - -# Function to reset the progress bar -def reset_progress_bar(): - progressbar_label.config(text="Progress: 0%") - progressbar['value'] = 0 - -# Countdown timer function -def countdown(): - global timer_duration, game_started - if timer_duration > 0 and game_started: - timer_label.config(text=f"Time left: {timer_duration} seconds") - countdown_label.config(text=str(timer_duration)) # Update countdown_label here - timer_duration -= 1 - root.after(1000, countdown) - -# Function to calculate WPM -def calculate_wpm(time_taken, word_count): - minutes = time_taken / 60 - wpm = (word_count / 5) / minutes - return round(wpm) - -# Initialize the GUI -root = tk.Tk() -root.geometry("800x400") -root.title("TypeRacer") - - -# Create the widgets with ttk themes -style = ttk.Style() -style.configure("TLabel", foreground="black", font=("Arial", 14)) -style.configure("TButton", font=("Arial", 16)) - -sentence_label = ttk.Label(root, text=current_sentence, wraplength=700, justify='left') -input_box = ttk.Entry(root, font=("Arial", 16), width=40) # Increase width -submit_button = ttk.Button(root, text="Submit", command=submit_score) -reset_button = ttk.Button(root, text="Reset", command=reset_game) -result_label = ttk.Label(root) -progressbar_label = ttk.Label(root, text="Progress: 0%") -progressbar = ttk.Progressbar(root, orient=tk.HORIZONTAL, length=200, mode="determinate") -timer_label = ttk.Label(root, text=f"Time left: {timer_duration} seconds") -countdown_label = ttk.Label(root, font=("Arial", 24), foreground="red") - -# Add the widgets to the GUI -sentence_label.pack(pady=20) -input_box.pack(pady=10) -submit_button.pack(side=tk.RIGHT, padx=10) -reset_button.pack(side=tk.RIGHT, padx=10) -result_label.pack(pady=10) -progressbar_label.pack(pady=10) -progressbar.pack(pady=10) -timer_label.pack(pady=10) -countdown_label.pack(pady=10) - -# Bind the typing event to the input_box -input_box.bind("", check_input) - -# Start the game -start_game() - -# Start the GUI event loop -root.mainloop() From 043f3bf06d1067783822c91b1feb095b83c89e93 Mon Sep 17 00:00:00 2001 From: kanchanrai7 <114416916+kanchanrai7@users.noreply.github.com> Date: Sat, 28 Oct 2023 00:03:51 +0530 Subject: [PATCH 3/3] Added Inventory Management System Using Mysql --- projects/inventory management/main.py | 115 ++++++++++++++++++ .../inventory management/requirements.txt | 2 + 2 files changed, 117 insertions(+) create mode 100644 projects/inventory management/main.py create mode 100644 projects/inventory management/requirements.txt diff --git a/projects/inventory management/main.py b/projects/inventory management/main.py new file mode 100644 index 000000000..e722d351d --- /dev/null +++ b/projects/inventory management/main.py @@ -0,0 +1,115 @@ +import tkinter +import mysql.connector as q +con=q.connect(host="localhost", user="root", passwd="", database="records") +cursor=con.cursor() + +#Adding record to an empty table(inventory) + +def ADD(): + pid=int(input("Enter the product id:")) + pname=input("Enter the product name: ") + pcost=int(input("Enter the product cost:")) + pqty=int(input("Enter the product quantity:")) + query="insert into inventory values({},'{}',{},{})".format(pid,pname,pcost,pqty) + cursor.execute(query) + con.commit() + print("Data Inserted successfully") + +#Displaying record in List form + +def Display(): + cursor.execute("select * from inventory") + record=cursor.fetchall() + print("ID"," ","Name"," ","Cost","","Quantity") + for i in record: + print(i) + print("Total Number of record=",cursor.rowcount) + +#Searching product on the basis of product code + +def Search(): + val=int(input("Enter the product code to search:")) + flag=0 + cursor.execute("select * from inventory") + record=cursor.fetchall() + for i in record: + if i[0]==val: + flag=1 + print("ID"," ","Name"," ","Cost","","Quantity") + print(i) + if flag==0: + print("---Record not found---") + +# Updating existing record on the basis of product ID + +def Update(): + code=int(input("Enter the product id to update:")) + pid=int(input("Enter product id:")) + pname=input("Enter product name:") + pcost=int(input("Enter the product cost:")) + pqty=int(input("Enter the product quantity:")) + query="update inventory set PID={},PNAME='{}',PCOST={},PQTY={} where PID={}".format(pid,pname,pcost,pqty,code) + cursor.execute(query) + con.commit() + print("Data Updated SuccessfullY") + +# Deleting records + +def Delete(): + val=int(input("Enter product ID whose records are to be deleted:")) + query="delete from inventory where PID={}".format(val) + cursor.execute(query) + con.commit() + if cursor.rowcount>0: + print("Record Successfully Deleted") + else: + print("Product not found") + +def check(): + if e1.get()=="Admin" and e2.get()=="1234": + win=tkinter.Tk() + win.title("Inventory") + win.configure(bg="SteelBlue1") + win.geometry('500x400') + login.destroy() + l=tkinter.Label(win,text='Welcome to Super Market',font=('Arial',18,'bold'),bg="SteelBlue1",fg="Black") + l.pack(side="top") + search=tkinter.Button(win,text="Search",font=('Arial',10,'bold'),command=Search,bg="azure") + add=tkinter.Button(win,text=' Add ',font=('Arial',10,'bold'),command=ADD,bg="azure") + update=tkinter.Button(win,text="Update",font=('Arial',10,'bold'),command=Update,bg='azure') + display=tkinter.Button(win,text="Display",font=('Arial',10,'bold'),command=Display,bg="azure") + delete=tkinter.Button(win,text=" Delete ",font=('Arial',10,'bold'),command=Delete,bg="azure") + e=tkinter.Button(win,text=' Exit ',font=('Arial',10,'bold'),command=win.destroy,bg="azure") + add.place(x=90,y=100) + display.place(x=90,y=200) + search.place(x=300,y=100) + update.place(x=195,y=150) + delete.place(x=300,y=200) + e.place(x=200,y=250) + win.mainloop() + + + else: + l1=tkinter.Label(login,text="Login Unsuccessful!!",font=("Arial",10,"bold"),fg="black",bg="light salmon") + l1.place(x=110,y=170) + + +login=tkinter.Tk() +login.geometry("400x220") +login.configure(bg="light salmon") +login.title("Authorised Login Only") +o=tkinter.Label(login,text='Login',font=('Arial',18,'bold'),bg='light salmon',fg="black") +o.pack(side='top') + +l1=tkinter.Label(login,text="Username",font=("Arial",10,'bold'),bg="white") +l1.place(x=10,y=50) +e1=tkinter.Entry(login,width=25,font=("Arial",10,'bold')) +e1.place(x=150,y=50) +l2=tkinter.Label(login,text= "Password",font=("Arial",10,'bold'),bg="white") +l2.place(x=10,y=80) +e2=tkinter.Entry(login,width=25,font=(10),show="*") +e2.place(x=150,y=80) +q=tkinter.Button(login,text="Submit",font=("Arial",10,"bold"),command=check) +q.place(x=225,y=120) +z=tkinter.Button(login,text="EXIT",font=("Arial",10,"bold"),command=login.destroy) +z.place(x=125,y=120) \ No newline at end of file diff --git a/projects/inventory management/requirements.txt b/projects/inventory management/requirements.txt new file mode 100644 index 000000000..a28b71cc9 --- /dev/null +++ b/projects/inventory management/requirements.txt @@ -0,0 +1,2 @@ +mysqlconnector.connect +tkinter \ No newline at end of file