tag:blogger.com,1999:blog-21054559760047498822024-03-14T07:50:05.268+05:30Python for Engineers Solve Problems by Coding Solutions - A Complete solution for python programmingManish T Ihttp://www.blogger.com/profile/05484750590005071795noreply@blogger.comBlogger376125tag:blogger.com,1999:blog-2105455976004749882.post-1792053072817324022024-01-01T09:30:00.000+05:302024-01-01T09:30:00.138+05:30Managing Students <p>import os</p><p>import platform</p><p>global listStd </p><p>listStd = ["Amal", "Appu", "Malavika", "Seetha"]</p><p>def manageStudent(): </p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>global bye</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>bye = "bye!!"</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>print(""" </span></p><p>Welcome To Student Management System<span style="white-space: pre;"> </span></p><p><br /></p><p>Enter 1 : To View Student's List </p><p>Enter 2 : To Add New Student </p><p>Enter 3 : To Search Student </p><p>Enter 4 : To Remove Student </p><p><span style="white-space: normal; white-space: pre;"> </span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>""")</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>try: </span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>userInput = int(input("Please Select An Above Option: "))</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>except ValueError:</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>exit("\nThat's Not A Number")</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>else:</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>print("\n") </span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>if(userInput == 1): </span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>print("List Students\n") </span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>for students in listStd:</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>print("=> {}".format(students))</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>elif(userInput == 2): </span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>newStd = input("Enter New Student: ")</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>if(newStd in listStd): </span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>print("\nThis Student {} Already In The Database".format(newStd)) </span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>else:<span style="white-space: pre;"> </span></span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>listStd.append(newStd)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>print("\n=> New Student {} Successfully Add \n".format(newStd))</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>for students in listStd:</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>print("=> {}".format(students))<span style="white-space: pre;"> </span></span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>elif(userInput == 3): </span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>srcStd = input("Enter Student Name To Search: ")</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>if(srcStd in listStd): </span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>print("\n=> Record Found Of Student {}".format(srcStd))</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>else:</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>print("\n=> No Record Found Of Student {}".format(srcStd)) </span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>elif(userInput == 4): </span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>rmStd = input("Enter Student Name To Remove: ")</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>if(rmStd in listStd): </span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>listStd.remove(rmStd)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>print("\n=> Student {} Successfully Deleted \n".format(rmStd))</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>for students in listStd:</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>print("=> {}".format(students))</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>else:</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>print("\n=> No Record Found of This Student {}".format(rmStd)) </span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span> </span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>elif(userInput < 1 or userInput > 4):</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>print("Please Enter Valid Option")<span style="white-space: pre;"> </span></span></p><p>manageStudent()</p><p>def runAgain():</p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>runAgn = input("\nwant To Run Again Y/n: ")</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>if(runAgn.lower() == 'y'):</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>if(platform.system() == "Windows"): </span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>print(os.system('cls')) </span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>else:</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>print(os.system('clear'))</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>manageStudent()</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>runAgain()</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>else:</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>quit(bye) </span></p><p>runAgain()<span style="white-space: pre;"> </span></p><div><br /></div>Divyahttp://www.blogger.com/profile/00563752234033470586noreply@blogger.com0tag:blogger.com,1999:blog-2105455976004749882.post-40481010525763535362023-10-31T09:30:00.002+05:302023-10-31T09:30:00.138+05:30Contact Storing <p>names = []</p><p>phone_numbers = []</p><p>num = 3</p><p>for i in range(num):</p><p> name = input("Name: ")</p><p> phone_number = input("Phone Number: ")</p><p> names.append(name)</p><p> phone_numbers.append(phone_number)</p><p>print("\nName\t\t\tPhone Number\n")</p><p>for i in range(num):</p><p> print("{}\t\t\t{}".format(names[i], phone_numbers[i]))</p><p>search_term = input("\nEnter search term: ")</p><p>print("Search result:")</p><p>if search_term in names:</p><p> index = names.index(search_term)</p><p> phone_number = phone_numbers[index]</p><p> print("Name: {}, Phone Number: {}".format(search_term, phone_number))</p><p>else:</p><p> print("Name Not Found")</p>Divyahttp://www.blogger.com/profile/00563752234033470586noreply@blogger.com0tag:blogger.com,1999:blog-2105455976004749882.post-1652116894935849472023-10-25T09:30:00.002+05:302023-10-25T09:30:00.143+05:30Tic Tac Toe Board<p>import turtle </p><p>ws=turtle.Screen()</p><p>t=turtle.Turtle()</p><p>t.color("Blue")</p><p>t.width("2")</p><p>t.speed(2)</p><p>for i in range(4):</p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>t.forward(300)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>t.left(90)</span></p><p>t.penup()</p><p>t.goto(0,100)</p><p>t.pendown()</p><p>t.forward(300)</p><p>t.penup()</p><p>t.goto(0,200)</p><p>t.pendown()</p><p>t.forward(300)</p><p>t.penup()</p><p>t.goto(100,0)</p><p>t.pendown()</p><p>t.left(90)</p><p>t.forward(300)</p><p>t.penup()</p><p>t.goto(200,0)</p><p>t.pendown()</p><p>t.forward(300)</p>Divyahttp://www.blogger.com/profile/00563752234033470586noreply@blogger.com0tag:blogger.com,1999:blog-2105455976004749882.post-72057584857209179532023-10-20T09:30:00.006+05:302023-10-20T09:30:00.145+05:30Sorting Hotel info Using Given Data<p>class Hotel :</p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>sortParam='name'</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>def __init__(self) -> None:</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>self.name=''</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>self.roomAvl=0</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>self.location=''</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>self.rating=int</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>self.pricePr=0</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>def __lt__(self,other):</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>getattr(self,Hotel.sortParam)<getattr(other,Hotel.sortParam)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>@classmethod</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>def sortByName(cls):</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>cls.sortParam='name'</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>@classmethod</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>def sortByRate(cls):</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>cls.sortParam='rating'</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>@classmethod</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>def sortByRoomAvailable(cls) :</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>cls.sortParam='roomAvl'</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>def __repr__(self) -> str:</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>return "PRHOTELS DATA:\nHotelName:{}\tRoom Available:{}\tLocation:{}\tRating:{}\tPricePer Room:{}".format(self.name,self.roomAvl,self.location,self.rating,self.pricePr)</span></p><p>class User:</p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>def __init__(self) -> None:</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>self.uname=''</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>self.uId=0</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>self.cost=0</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>def __repr__(self) -> str:</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>return "UserName:{}\tUserId:{}\tBooking Cost:{}".format(self.uname,self.uId,self.cost)</span></p><p>def PrintHotelData(hotels):</p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>for h in hotels:</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>print(h)</span></p><p>def SortHotelByName(hotels):</p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>print("SORT BY NAME:")</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>Hotel.sortByName()</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>hotels.sort()</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>PrintHotelData(hotels)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>print()</span></p><p>def SortHotelByRating(hotels):</p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>print("SORT BY A RATING:")</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>Hotel.sortByRate()</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>hotels.sort()</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>PrintHotelData(hotels)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>print()</span></p><p>def PrintHotelBycity(s,hotels):</p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>print("HOTELS FOR {} LOCATION ARE:".format(s))</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>hotelsByLoc=[h for h in hotels if h.location==s]</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>PrintHotelData(hotelsByLoc)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>print()</span></p><p>def SortByRoomAvailable(hotels):</p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>print("SORT BY ROOM AVAILABLE:")</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>Hotel.sortByRoomAvailable()</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>hotels.sort()</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>PrintHotelData(hotels)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>print()</span></p><p>def PrintUserData(userName, userId, bookingCost, hotels):</p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>users=[]</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>for i in range(3) :</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>u=User()</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>u.uname = userName[i]</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>u.uId = userId[i]</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>u.cost = bookingCost[i]</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>users.append(u)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>for i in range(len(users)) :</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>print(users[i],"\tHotel name:",hotels[i].name)</span></p><p>def HotelManagement(userName,</p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>userId,</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>hotelName,</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>bookingCost,</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>rooms,</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>locations,</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>ratings,</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>prices):</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>hotels=[]</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>for i in range(3) :</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>h=Hotel()</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>h.name = hotelName[i]</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>h.roomAvl = rooms[i]</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>h.location = locations[i]</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>h.rating = ratings[i]</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>h.pricePr = prices[i]</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>hotels.append(h)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>print()</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>PrintHotelData(hotels)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>SortHotelByName(hotels)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>SortHotelByRating(hotels)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>PrintHotelBycity("Bangalore",</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>hotels)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>SortByRoomAvailable(hotels)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>PrintUserData(userName,</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>userId,</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>bookingCost,</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>hotels)</span></p><p>if __name__ == '__main__':</p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>userName = ["U1", "U2", "U3"]</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>userId = [2, 3, 4] </span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>hotelName = ["H1", "H2", "H3"] </span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>bookingCost = [1000, 1200, 1100]</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>rooms = [4, 5, 6] </span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>locations = ["Bangalore",</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>"Bangalore",</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>"Mumbai"]</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>ratings = [5, 5, 3]</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>prices = [100, 200, 100] </span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>HotelManagement(userName, userId,</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>hotelName, bookingCost,</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>rooms, locations,</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>ratings, prices)</span></p><div><br /></div>Divyahttp://www.blogger.com/profile/00563752234033470586noreply@blogger.com0tag:blogger.com,1999:blog-2105455976004749882.post-27335905730406743202023-10-16T09:30:00.002+05:302023-10-16T09:30:00.138+05:30Sales Management App<p>import tkinter as tk</p><p>from tkinter import messagebox</p><p>import sqlite3</p><p>root_window = tk.Tk()</p><p>root_window.title("Sales Management App")</p><p>root_window.geometry("720x750")</p><p>name_entry_text = tk.StringVar()</p><p>id_entry_text = tk.StringVar()</p><p>quantity_sold_entry_text = tk.StringVar()</p><p>quantity_left_entry_text = tk.StringVar()</p><p>price_entry_text = tk.StringVar()</p><p>today_sales_quantity_entry_text = tk.StringVar()</p><p>today_sales_total_price_entry_text = tk.StringVar()</p><p>week_sales_quantity_entry_text = tk.StringVar()</p><p>week_sales_total_price_entry_text = tk.StringVar()</p><p>month_sales_quantity_entry_text = tk.StringVar()</p><p>month_sales_total_price_entry_text = tk.StringVar()</p><p>delete_entry = tk.StringVar()</p><p>name_entry = tk.Entry(root_window, textvariable=name_entry_text)</p><p>id_entry = tk.Entry(root_window, textvariable=id_entry_text)</p><p>quantity_sold_entry = tk.Entry(root_window, textvariable=quantity_sold_entry_text)</p><p>quantity_left_entry = tk.Entry(root_window, textvariable=quantity_left_entry_text)</p><p>price_entry = tk.Entry(root_window, textvariable=price_entry_text)</p><p>today_sales_quantity_entry = tk.Entry(root_window, textvariable=today_sales_quantity_entry_text)</p><p>today_sales_total_price_entry = tk.Entry(root_window, textvariable=today_sales_total_price_entry_text)</p><p>week_sales_quantity_entry = tk.Entry(root_window, textvariable=week_sales_quantity_entry_text)</p><p>week_sales_total_price_entry = tk.Entry(root_window, textvariable=week_sales_total_price_entry_text)</p><p>month_sales_quantity_entry = tk.Entry(root_window, textvariable=month_sales_quantity_entry_text)</p><p>month_sales_total_price_entry = tk.Entry(root_window, textvariable=month_sales_total_price_entry_text)</p><p>delete_entry = tk.Entry(root_window, textvariable=delete_entry, width=20)</p><p>delete_entry.grid(row=6, column=3, padx=10, columnspan=3, rowspan=2)</p><p>delete_entry.insert(0, 'Enter id to delete')</p><p>name_label = tk.Label(root_window, text="Product name")</p><p>id_label = tk.Label(root_window, text="Product ID")</p><p>quantity_sold_label = tk.Label(root_window, text="Quantity sold")</p><p>quantity_left_label = tk.Label(root_window, text="Quantity left")</p><p>price_label = tk.Label(root_window, text="Price")</p><p>today_sales_quantity_label = tk.Label(root_window, text="Today's Sales(quantity)")</p><p>today_sales_total_price_label = tk.Label(root_window, text="Today's Sales(Total Price)")</p><p>week_sales_quantity_label = tk.Label(root_window, text="Week Sales(quantity)")</p><p>week_sales_total_price_label = tk.Label(root_window, text="Week Sales(Total Price)")</p><p>month_sales_quantity_label = tk.Label(root_window, text="Month Sales(quantity)")</p><p>month_sales_total_price_label = tk.Label(root_window, text="Month Sales(Total Price)")</p><p>product_list_label = tk.Label(root_window, text='Product List', font=(30), borderwidth=1, relief="solid", width=50)</p><p>product_list_label.grid(row=12, column=0, columnspan=50, pady=20)</p><p>pdt_name = tk.Label(root_window, text='Product Name', borderwidth=1, relief="solid")</p><p>pdt_id = tk.Label(root_window, text='Product ID', borderwidth=1, relief="solid")</p><p>pdt_price = tk.Label(root_window, text='Product Price', borderwidth=1, relief="solid")</p><p>pdt_sales_quantity = tk.Label(root_window, text="Today's Sales(Quantity)", borderwidth=1, relief="solid")</p><p>def Refresh():</p><p> conn = sqlite3.connect('database.db')</p><p> cursor = conn.cursor()</p><p> cursor.execute("CREATE TABLE IF NOT EXISTS products (name TEXT, id TEXT PRIMARY KEY, quantitySold TEXT, quantityLeft TEXT, price TEXT, todaySalesQuantity TEXT, todaySalesTotalPrice TEXT, weekSalesQuantity TEXT, weekSalesTotalPrice TEXT, monthSalesQuantity TEXT, monthSalesTotalPrice TEXT)")</p><p> cursor.execute('SELECT * FROM products')</p><p> products = cursor.fetchall()</p><p> for i in range(len(products)):</p><p> tk.Label(root_window, text=products[i][0]).grid(row=i+14, column=0)</p><p> tk.Label(root_window, text=products[i][1]).grid(row=i+14, column=1)</p><p> tk.Label(root_window, text=products[i][4]).grid(row=i+14, column=2)</p><p> tk.Label(root_window, text=products[i][5]).grid(row=i+14, column=3)</p><p> conn.close()</p><p>def show_message(title, message):</p><p> messagebox.showerror(title, message)</p><p>def add_product():</p><p> try:</p><p> conn = sqlite3.connect("database.db")</p><p> cursor = conn.cursor()</p><p> cursor.execute("INSERT INTO products (name, id, quantitySold, quantityLeft, price, todaySalesQuantity, todaySalesTotalPrice, weekSalesQuantity, weekSalesTotalPrice, monthSalesQuantity, monthSalesTotalPrice) VALUES (?, ?, ?, ?,?,?,?,?,?,?,?)", (str(name_entry_text.get()), str(id_entry_text.get()), str(quantity_sold_entry_text.get()), str(quantity_left_entry_text.get()), str(price_entry_text.get()), str(today_sales_quantity_entry_text.get()), str(today_sales_total_price_entry_text.get()), str(week_sales_quantity_entry_text.get()), str(week_sales_total_price_entry_text.get()), str(month_sales_quantity_entry_text.get()), str(month_sales_total_price_entry_text.get())))</p><p> conn.commit()</p><p> except sqlite3.Error as e:</p><p> show_message('Sqlite error', e)</p><p> finally:</p><p> Refresh()</p><p> conn.close()</p><p>def delete_product():</p><p> try:</p><p> conn = sqlite3.connect("database.db")</p><p> cursor = conn.cursor()</p><p> cursor.execute('SELECT * FROM products')</p><p> cursor.execute("DELETE FROM products WHERE id = ?", (str(delete_entry.get())))</p><p> conn.commit()</p><p> show_message('Success', 'Product deleted')</p><p> conn.close()</p><p> Refresh()</p><p> except sqlite3.Error as e:</p><p> show_message('Sqlite error', e)</p><p> finally:</p><p> conn.close()</p><p> Refresh()</p><p>def update():</p><p> price = price_entry_text.get()</p><p> quantity_sold = quantity_sold_entry_text.get()</p><p> quantity_left = quantity_left_entry_text.get()</p><p> today_sales_quantity = today_sales_quantity_entry_text.get()</p><p> week_sales_quantity = week_sales_quantity_entry_text.get()</p><p> month_sales_quantity = month_sales_quantity_entry_text.get()</p><p> if len(price) < 1 or len(quantity_sold) < 1 or len(quantity_left) < 1 or len(today_sales_quantity) < 1 or len(week_sales_quantity) < 1 or len(month_sales_quantity) < 1:</p><p> show_message('Python error!', 'Please enter values for all fields')</p><p> return</p><p> try:</p><p> price = int(price)</p><p> quantity_sold = int(quantity_sold)</p><p> quantity_left = int(quantity_left)</p><p> today_sales_quantity = int(today_sales_quantity)</p><p> week_sales_quantity = int(week_sales_quantity)</p><p> month_sales_quantity = int(month_sales_quantity)</p><p> conn = sqlite3.connect('database.db')</p><p> c = conn.cursor()</p><p> c.execute("UPDATE products SET name=?, id=?, quantitySold=?, quantityLeft=?, price=?, todaySalesQuantity=?, todaySalesTotalPrice=?, weekSalesQuantity=?, weekSalesTotalPrice=?, monthSalesQuantity=?, monthSalesTotalPrice=? WHERE id=?", (str(name_entry_text.get()), str(id_entry_text.get()), str(quantity_sold_entry_text.get()), str(quantity_left_entry_text.get()), str(price_entry_text.get()), str(today_sales_quantity_entry_text.get()), str(today_sales_total_price_entry_text.get()), str(week_sales_quantity_entry_text.get()), str(week_sales_total_price_entry_text.get()), str(month_sales_quantity_entry_text.get()), str(month_sales_total_price_entry_text.get()), str(id_entry_text.get())))</p><p> conn.commit()</p><p> Refresh()</p><p> show_message('Success', 'Product updated')</p><p> conn.close()</p><p> except sqlite3.Error as e:</p><p> show_message('Sqlite error', e)</p><p> finally:</p><p> Refresh()</p><p> conn.close()</p><p>def calculate():</p><p> price = price_entry_text.get()</p><p> quantity_sold = quantity_sold_entry_text.get()</p><p> quantity_left = quantity_left_entry_text.get()</p><p> today_sales_quantity = today_sales_quantity_entry_text.get()</p><p> week_sales_quantity = week_sales_quantity_entry_text.get()</p><p> month_sales_quantity = month_sales_quantity_entry_text.get()</p><p> if len(price) < 1 or len(quantity_sold) < 1 or len(quantity_left) < 1 or len(today_sales_quantity) < 1 or len(week_sales_quantity) < 1 or len(month_sales_quantity) < 1:</p><p> show_message('Python error!', 'Please enter values for all fields')</p><p> return</p><p> try:</p><p> price = int(price)</p><p> quantity_sold = int(quantity_sold)</p><p> quantity_left = int(quantity_left)</p><p> today_sales_quantity = int(today_sales_quantity)</p><p> week_sales_quantity = int(week_sales_quantity)</p><p> month_sales_quantity = int(month_sales_quantity)</p><p> except:</p><p> show_message('Python error!', 'Please enter integer values in these fields-> Price, Today Sales(Quantity), Week Sales(Quantity), Month Sales(Quantity)')</p><p> return</p><p> today_sales_total_price = price * today_sales_quantity</p><p> week_sales_total_price = price * week_sales_quantity</p><p> month_sales_total_price = price * month_sales_quantity</p><p><br /></p><p> today_sales_total_price_entry_text.set(today_sales_total_price)</p><p> week_sales_total_price_entry_text.set(week_sales_total_price)</p><p> month_sales_total_price_entry_text.set(month_sales_total_price)</p><p> add_button.config(state='normal')</p><p>Refresh()</p><p>update_button = tk.Button(text='UPDATE', width=20, height=2, command=update)</p><p>delete_button = tk.Button(text='DELETE', width=20,height=2, command=delete_product)</p><p>add_button = tk.Button(text='ADD', width=20, height=2, command=add_product)</p><p>add_button.config(state='disabled')</p><p>calculate_button = tk.Button(text='Verify And Calculate Prices', width=25, height=2, command=calculate)</p><p>refresh_button = tk.Button(text='Refresh Table', width=25, height=2, command=Refresh)</p><p>name_label.grid(row=0, column=0, padx=10, pady=10, sticky='w')</p><p>id_label.grid(row=1, column=0, padx=10, pady=10, sticky='w')</p><p>quantity_sold_label.grid(row=2, column=0, padx=10, pady=10, sticky='w')</p><p>quantity_left_label.grid(row=3, column=0, padx=10, pady=10, sticky='w')</p><p>price_label.grid(row=4, column=0, padx=10, pady=10, sticky='w')</p><p>today_sales_quantity_label.grid(row=5, column=0, padx=10, pady=10, sticky='w')</p><p>today_sales_total_price_label.grid(row=6, column=0, padx=10, pady=10, sticky='w')</p><p>week_sales_quantity_label.grid(row=7, column=0, padx=10, pady=10, sticky='w')</p><p>week_sales_total_price_label.grid(row=8, column=0, padx=10, pady=10, sticky='w')</p><p>month_sales_quantity_label.grid(row=9, column=0, padx=10, pady=10, sticky='w')</p><p>month_sales_total_price_label.grid(row=10, column=0, padx=10, pady=10, sticky='w')</p><p>name_entry.grid(row=0, column=1, padx=10, pady=10, sticky='w')</p><p>id_entry.grid(row=1, column=1, padx=10, pady=10, sticky='w')</p><p>quantity_sold_entry.grid(row=2, column=1, padx=10, pady=10, sticky='w')</p><p>quantity_left_entry.grid(row=3, column=1, padx=10, pady=10, sticky='w')</p><p>price_entry.grid(row=4, column=1, padx=10, pady=10, sticky='w')</p><p>today_sales_quantity_entry.grid(row=5, column=1, padx=10, pady=10, sticky='w')</p><p>today_sales_total_price_entry.grid(row=6, column=1, padx=10, pady=10, sticky='w')</p><p>today_sales_total_price_entry.config(state='disabled')</p><p>week_sales_quantity_entry.grid(row=7, column=1, padx=10, pady=10, sticky='w')</p><p>week_sales_total_price_entry.grid(row=8, column=1, padx=10, pady=10, sticky='w')</p><p>week_sales_total_price_entry.config(state='disabled')</p><p>month_sales_quantity_entry.grid(row=9, column=1, padx=10, pady=10, sticky='w')</p><p>month_sales_total_price_entry.grid(row=10, column=1, padx=10, pady=10, sticky='w')</p><p>month_sales_total_price_entry.config(state='disabled')</p><p>update_button.grid(row=3, column=2, rowspan=2, padx=15)</p><p>delete_button.grid(row=6, column=2, rowspan=2, padx=15)</p><p>calculate_button.grid(row=11, column=0, columnspan=2)</p><p>add_button.grid(row=11, column=2)</p><p>refresh_button.grid(row=11, column=3)</p><p>pdt_name.grid(row=13, column=0)</p><p>pdt_id.grid(row=13, column=1)</p><p>pdt_price.grid(row=13, column=2)</p><p>pdt_sales_quantity.grid(row=13, column=3)</p><p>root_window.mainloop()</p>Divyahttp://www.blogger.com/profile/00563752234033470586noreply@blogger.com0tag:blogger.com,1999:blog-2105455976004749882.post-157402833869908102023-10-09T09:30:00.002+05:302023-10-09T09:30:00.142+05:30App For Download File from URL<p>from tkinter import *</p><p>from tkinter import messagebox</p><p>from PIL import ImageTk, Image</p><p>import tkinter.font as font</p><p>import requests</p><p>import re</p><p>import validators</p><p>import os</p><p>from urllib.parse import urlparse</p><p>root = Tk()</p><p>root.title("Download File from URL")</p><p>icon = PhotoImage(file='image.png')</p><p>root.iconphoto(False, icon)</p><p>root.minsize(600, 500)</p><p>root.maxsize(600, 500)</p><p>HEIGHT = 500</p><p>WIDTH = 500</p><p>FONT = font.Font(family="Comic Sans MS", size="10", weight="bold")</p><p>canvas = Canvas(root, height=HEIGHT, width=WIDTH)</p><p>canvas.pack()</p><p>background_image = ImageTk.PhotoImage(</p><p> Image.open(r"image.jpg"))</p><p>background_label = Label(root, image=background_image)</p><p>background_label.place(relwidth=1, relheight=1)</p><p>frame = Frame(root, bg="yellow", bd=5)</p><p>frame.place(relx=0.5, rely=0.1, relwidth=0.80, relheight=0.25, anchor="n")</p><p>label_up = Label(frame)</p><p>label_up.place(relwidth=1, relheight=1)</p><p>label1 = Label(frame, text="Enter the URL", font=FONT, bd=5,</p><p> bg="#fc034e", highlightbackground="#d9138a", fg="black")</p><p>label1.place(relx=0.1, rely=0.1, relwidth=0.25, relheight=0.25)</p><p>label2 = Label(frame, text="Enter Filename", font=FONT, bd=5,</p><p> bg="#fc034e", highlightbackground="#d9138a", fg="black")</p><p>label2.place(relx=0.1, rely=0.64, relwidth=0.25, relheight=0.25)</p><p>entry1 = Entry(frame, font=FONT, fg="#001a4d")</p><p>entry1.place(relx=0.54, rely=0.1, relwidth=0.4, relheight=0.25)</p><p>entry2 = Entry(frame, font=FONT, fg="#001a4d")</p><p>entry2.place(relx=0.54, rely=0.64, relwidth=0.4, relheight=0.25)</p><p>def download(url, name):</p><p> valid = validators.url(url)</p><p> if (valid != True):</p><p> messagebox.showerror("Invalid URL", "URL is invalid")</p><p> elif (url == ""):</p><p> messagebox.showerror("No valid URL", "URL cannot be empty")</p><p> else:</p><p> response = requests.get(url, allow_redirects=True)</p><p> rhead = response.headers['Content-Type']</p><p> if (canbedownloaded(rhead)):</p><p> if (name == ""):</p><p> a = urlparse(url)</p><p> name = os.path.basename(a.path)</p><p> file_data = rhead.split('/')</p><p> ext = file_data[1]</p><p> filename = name+'.'+ext</p><p> open(filename, "wb").write(response.content)</p><p> label_down['text'] = f"Your file {filename}\n has been downloaded successfully."</p><p> else:</p><p> label_down['text'] = "This file is invalid. It can not be downloaded."</p><p>def canbedownloaded(rhead):</p><p> if 'text' in rhead.lower():</p><p> return False</p><p> if 'html' in rhead.lower():</p><p> return False</p><p> return True</p><p>def clear():</p><p> entry1.delete(0, END)</p><p> entry2.delete(0, END)</p><p> label_down['text'] = ""</p><p>button1 = Button(root, text="DOWNLOAD", font=FONT, bg="pink", fg="black", activeforeground="pink",</p><p> activebackground="black", command=lambda: download(entry1.get(), entry2.get()))</p><p>button1.place(relx=0.25, rely=0.4, relwidth=0.19, relheight=0.07)</p><p>button2 = Button(root, text="CLEAR", font=FONT, bg="pink", fg="black",</p><p> activeforeground="pink", activebackground="black", command=clear)</p><p>button2.place(relx=0.55, rely=0.4, relwidth=0.19, relheight=0.07)</p><p>lower_frame = Frame(root, bg="yellow", bd=10)</p><p>lower_frame.place(relx=0.5, rely=0.53, relwidth=0.8,</p><p> relheight=0.25, anchor="n")</p><p>label_down = Label(lower_frame, font=FONT, fg="#001a4d",</p><p> anchor="nw", justify="left", bd=4)</p><p>label_down.place(relwidth=1, relheight=1)</p><p>root.mainloop()</p>Divyahttp://www.blogger.com/profile/00563752234033470586noreply@blogger.com0tag:blogger.com,1999:blog-2105455976004749882.post-10425547965881314942023-09-30T09:30:00.004+05:302023-09-30T09:30:00.149+05:30Loan Managing App<p>import sqlite3</p><p>from tkinter import *</p><p>from tkinter import ttk, messagebox</p><p>class LoanManager:</p><p> def __init__(self, root):</p><p> self.root = root</p><p> self.root.title("Loan Managing app")</p><p> self.root.geometry("1350x720+0+0")</p><p> title = Label(self.root, text="Loan Managing App", font=(</p><p> "Comic Sans MS", 20, ), bd=8, bg='black', fg='white')</p><p> title.pack(side=TOP, fill=X)</p><p> self.LoanId = StringVar()</p><p> self.name = StringVar()</p><p> self.mob = StringVar()</p><p> self.aadhar = StringVar()</p><p> self.add = StringVar()</p><p> self.pin = StringVar()</p><p> self.amount = StringVar()</p><p> self.year = StringVar()</p><p> self.rate = StringVar()</p><p> self.mpay = StringVar()</p><p> self.tpay = StringVar()</p><p> Detail_F = Frame(self.root, bd=4, relief=RIDGE, bg='light blue')</p><p> Detail_F.place(x=10, y=90, width=520, height=620)</p><p> lbl_id = Label(Detail_F, text="Loan Id", font=("Comic Sans MS", 12, ))</p><p> lbl_id.grid(row=0, column=0, pady=10, padx=20, sticky="w")</p><p> txt_id = Entry(Detail_F, font=("Comic Sans MS", 10, ),</p><p> bd=3, textvariable=self.LoanId)</p><p> txt_id.grid(row=0, column=1, pady=10, sticky="w")</p><p> lbl_name = Label(Detail_F, text="Full Name",</p><p> font=("Comic Sans MS", 12, ))</p><p> lbl_name.grid(row=1, column=0, pady=10, padx=20, sticky="w")</p><p> txt_name = Entry(Detail_F, font=("Comic Sans MS", 10, ),</p><p> bd=3, textvariable=self.name)</p><p> txt_name.grid(row=1, column=1, pady=10, sticky="w")</p><p> lbl_mob = Label(Detail_F, text="Mobile No.",</p><p> font=("Comic Sans MS", 12, ))</p><p> lbl_mob.grid(row=2, column=0, pady=10, padx=20, sticky="w")</p><p> txt_mob = Entry(Detail_F, font=("Comic Sans MS", 10, ),</p><p> bd=3, textvariable=self.mob)</p><p> txt_mob.grid(row=2, column=1, pady=10, sticky="w")</p><p> lbl_aa = Label(Detail_F, text="Aadhar No.",</p><p> font=("Comic Sans MS", 12, ))</p><p> lbl_aa.grid(row=3, column=0, pady=10, padx=20, sticky="w")</p><p> txt_aa = Entry(Detail_F, font=("Comic Sans MS", 10, ),</p><p> bd=3, textvariable=self.aadhar)</p><p> txt_aa.grid(row=3, column=1, pady=10, sticky="w")</p><p> lbl_add = Label(Detail_F, text="Address", font=("Comic Sans MS", 12, ))</p><p> lbl_add.grid(row=4, column=0, pady=10, padx=20, sticky="w")</p><p> txt_add = Entry(Detail_F, font=("Comic Sans MS", 10, ),</p><p> bd=3, textvariable=self.add)</p><p> txt_add.grid(row=4, column=1, pady=10, sticky="w")</p><p> lbl_pin = Label(Detail_F, text="PinCode", font=("Comic Sans MS", 12, ))</p><p> lbl_pin.grid(row=5, column=0, pady=10, padx=20, sticky="w")</p><p> txt_pin = Entry(Detail_F, font=("Comic Sans MS", 10, ),</p><p> bd=3, textvariable=self.pin)</p><p> txt_pin.grid(row=5, column=1, pady=10, sticky="w")</p><p> lbl_amount = Label(Detail_F, text="Amount of Loan",</p><p> font=("Comic Sans MS", 12, ))</p><p> lbl_amount.grid(row=6, column=0, pady=10, padx=20, sticky="w")</p><p> txt_amount = Entry(Detail_F, font=(</p><p> "Comic Sans MS", 10, ), bd=3, textvariable=self.amount)</p><p> txt_amount.grid(row=6, column=1, pady=10, sticky="w")</p><p> lbl_time = Label(Detail_F, text="Number of years",</p><p> font=("Comic Sans MS", 12, ))</p><p> lbl_time.grid(row=7, column=0, pady=10, padx=20, sticky="w")</p><p> txt_time = Entry(Detail_F, font=("Comic Sans MS", 10,</p><p> ), bd=3, textvariable=self.year)</p><p> txt_time.grid(row=7, column=1, pady=10, sticky="w")</p><p> lbl_rate = Label(Detail_F, text="Interest Rate",</p><p> font=("Comic Sans MS", 12, ))</p><p> lbl_rate.grid(row=8, column=0, pady=10, padx=20, sticky="w")</p><p> txt_rate = Entry(Detail_F, font=("Comic Sans MS", 10,</p><p> ), bd=3, textvariable=self.rate)</p><p> txt_rate.grid(row=8, column=1, pady=10, sticky="w")</p><p> lbl_Mp = Label(Detail_F, text="Monthly Payment",</p><p> font=("Comic Sans MS", 12, ))</p><p> lbl_Mp.grid(row=9, column=0, pady=10, padx=20, sticky="w")</p><p> txt_Mp = Label(Detail_F, font=("Comic Sans MS", 10, ),</p><p> bd=3, state=DISABLED, textvariable=self.mpay)</p><p> txt_Mp.grid(row=9, column=1, pady=10, sticky="w")</p><p> lbl_tp = Label(Detail_F, text="Total Payment",</p><p> font=("Comic Sans MS", 12, ))</p><p> lbl_tp.grid(row=10, column=0, pady=10, padx=20, sticky="w")</p><p> txt_tp = Label(Detail_F, font=("Comic Sans MS", 10, ),</p><p> bd=3, state=DISABLED, textvariable=self.tpay)</p><p> txt_tp.grid(row=10, column=1, pady=10, sticky="w")</p><p> recordFrame = Frame(self.root, bd=5, relief=RIDGE)</p><p> recordFrame.place(x=535, y=100, width=810, height=530)</p><p><br /></p><p> yscroll = Scrollbar(recordFrame, orient=VERTICAL)</p><p> self.employee_table = ttk.Treeview(recordFrame, columns=(</p><p> "empId", "name", "years", "rate", "Mpayment", "Tpayment", "mobile"), yscrollcommand=yscroll.set)</p><p> yscroll.pack(side=RIGHT, fill=Y)</p><p> yscroll.config(command=self.employee_table.yview)</p><p> self.employee_table.heading("empId", text="customer Id")</p><p> self.employee_table.heading("name", text="Name")</p><p> self.employee_table.heading("years", text="Number of Years")</p><p> self.employee_table.heading("rate", text="Interest Rate")</p><p> self.employee_table.heading("Mpayment", text="Monthly Payment")</p><p> self.employee_table.heading("Tpayment", text="Total Payment")</p><p> self.employee_table.heading("mobile", text="Mobile No.")</p><p> self.employee_table['show'] = 'headings'</p><p> self.employee_table.column("empId", width=100)</p><p> self.employee_table.column("name", width=100)</p><p> self.employee_table.column("years", width=100)</p><p> self.employee_table.column("rate", width=100)</p><p> self.employee_table.column("Mpayment", width=110)</p><p> self.employee_table.column("Tpayment", width=100)</p><p> self.employee_table.column("mobile", width=100)</p><p> self.employee_table.pack(fill=BOTH, expand=1)</p><p> self.fetch_data()</p><p> self.employee_table.bind("<ButtonRelease-1>", self.get_cursor)</p><p> btnFrame = Frame(self.root, bd=5, relief=RIDGE)</p><p> btnFrame.place(x=700, y=630, width=480, height=60)</p><p> btn1 = Button(btnFrame, text='Add record', font='arial 12 bold',</p><p> bg='black', fg='white', width=9, command=self.addrecord)</p><p> btn1.grid(row=0, column=0, padx=10, pady=10)</p><p> btn2 = Button(btnFrame, text='Update', font='arial 12 bold',</p><p> bg='black', fg='white', width=9, command=self.update)</p><p> btn2.grid(row=0, column=1, padx=8, pady=10)</p><p> btn3 = Button(btnFrame, text='Delete', font='arial 12 bold',</p><p> bg='black', fg='white', width=9, command=self.delete)</p><p> btn3.grid(row=0, column=2, padx=8, pady=10)</p><p> btn4 = Button(btnFrame, text='Reset', font='arial 12 bold',</p><p> bg='black', fg='white', width=9, command=self.reset)</p><p> btn4.grid(row=0, column=3, padx=8, pady=10)</p><p> def total(self):</p><p> p = int(self.amount.get())</p><p> r = int(self.rate.get())</p><p> n = int(self.year.get())</p><p> t = (p*r*n*10)/100</p><p> m = (p+t)/(n*10)</p><p> self.mpay.set(str(round(m, 2)))</p><p> self.tpay.set(str(t+p))</p><p> def addrecord(self):</p><p> if self.LoanId.get() == '' or self.name.get() == '' or self.mob.get() == '' or self.aadhar.get() == '' or self.add.get() == '' or self.pin.get() == '':</p><p> messagebox.showerror('Error', 'Please enter details ?')</p><p> else:</p><p> self.total()</p><p> con = sqlite3.connect('loanDetails.db')</p><p> cur = con.cursor()</p><p> cur.execute("Select * from customer")</p><p> rows = cur.fetchall()</p><p> for row in rows:</p><p> if row[0] == self.LoanId.get():</p><p> messagebox.showerror(</p><p> 'Error', 'Duplicates not allowed')</p><p> return</p><p> cur.execute("insert into customer values(?,?,?,?,?,?,?,?,?,?,?)", (</p><p> self.LoanId.get(),</p><p> self.name.get(),</p><p> self.mob.get(),</p><p> self.aadhar.get(),</p><p> self.add.get(),</p><p> self.pin.get(),</p><p> self.amount.get(),</p><p> self.year.get(),</p><p> self.rate.get(),</p><p> self.mpay.get(),</p><p> self.tpay.get(),</p><p> ))</p><p> con.commit()</p><p> self.fetch_data()</p><p> con.close()</p><p> def fetch_data(self):</p><p> con = sqlite3.connect('loanDetails.db')</p><p> cur = con.cursor()</p><p> cur.execute("select Loan_Id , Name , Year , Rate , Monthly_Payment , Total_Payment , MobileNumber , AadharNumber , Address , Pincode , Amount from customer")</p><p> rows = cur.fetchall()</p><p> if len(rows) != 0:</p><p> self.employee_table.delete(*self.employee_table.get_children())</p><p> for row in rows:</p><p> self.employee_table.insert('', END, values=row)</p><p> con.commit()</p><p> con.close()</p><p> def update(self):</p><p> if self.LoanId.get() == '':</p><p> messagebox.showerror('Error', 'Select a record to update !')</p><p> else:</p><p> self.total()</p><p> con = sqlite3.connect('loanDetails.db')</p><p> cur = con.cursor()</p><p> cur.execute("update customer set Name = ?, MobileNumber = ?, AadharNumber = ?, Address = ?, Pincode = ?, Amount = ?, Year = ?, Rate = ?, Total_Payment = ?, Monthly_Payment = ? where Loan_Id = ?", (</p><p> self.name.get(),</p><p> self.mob.get(),</p><p> self.aadhar.get(),</p><p> self.add.get(),</p><p> self.pin.get(),</p><p> self.amount.get(),</p><p> self.year.get(),</p><p> self.rate.get(),</p><p> self.tpay.get(),</p><p> self.mpay.get(),</p><p> self.LoanId.get()</p><p> ))</p><p> messagebox.showinfo(</p><p> 'Info', f'Record {self.LoanId.get()} Updated Successfully')</p><p> con.commit()</p><p> con.close()</p><p> self.fetch_data()</p><p> self.reset()</p><p> def delete(self):</p><p> if self.LoanId.get() == '':</p><p> messagebox.showerror(</p><p> 'Error', 'Enter customer ID to delete the records')</p><p> else:</p><p> con = sqlite3.connect('loanDetails.db')</p><p> cur = con.cursor()</p><p> cur.execute("delete from customer where Loan_Id = ?",</p><p> (self.LoanId.get(),))</p><p> con.commit()</p><p> con.close()</p><p> self.fetch_data()</p><p> self.reset()</p><p> def reset(self):</p><p> self.LoanId.set('')</p><p> self.name.set('')</p><p> self.mob.set('')</p><p> self.aadhar.set('')</p><p> self.add.set('')</p><p> self.pin.set('')</p><p> self.amount.set('')</p><p> self.year.set('')</p><p> self.rate.set('')</p><p> self.mpay.set('')</p><p> self.tpay.set('')</p><p> def get_cursor(self, ev):</p><p> cursor_row = self.employee_table.focus()</p><p> content = self.employee_table.item(cursor_row)</p><p> row = content['values']</p><p> self.LoanId.set(row[0])</p><p> self.name.set(row[1])</p><p> self.year.set(row[2])</p><p> self.rate.set(row[3])</p><p> self.mpay.set(row[4])</p><p> self.tpay.set(row[5])</p><p> self.mob.set(row[6])</p><p> self.aadhar.set(row[7])</p><p> self.add.set(row[8])</p><p> self.pin.set(row[9])</p><p> self.amount.set(row[10])</p><p>class Login():</p><p> def __init__(self, root):</p><p> self.root = root</p><p> self.root.title("Loan Managing app")</p><p> self.username = StringVar()</p><p> self.password = StringVar()</p><p> Label(self.root, text="Username:").grid(</p><p> row=0, column=0, padx=10, pady=10)</p><p> Entry(self.root, textvariable=self.username).grid(</p><p> row=0, column=1, padx=10, pady=10)</p><p> Label(self.root, text="Password:").grid(</p><p> row=1, column=0, padx=10, pady=10)</p><p> Entry(self.root, textvariable=self.password,</p><p> show="*").grid(row=1, column=1, padx=10, pady=10)</p><p> Button(self.root, text="Login", command=self.login).grid(</p><p> row=2, column=1, padx=10, pady=10)</p><p> def login(self):</p><p> if self.username.get() == "root" and self.password.get() == "root":</p><p> root.destroy()</p><p> nroot = Tk()</p><p> LoanManager(nroot)</p><p> else:</p><p> messagebox.showerror("Error", "Invalid username or password")</p><p>con = sqlite3.connect('loanDetails.db')</p><p>cur = con.cursor()</p><p>cur.execute('create table if not exists customer(Loan_Id varchar(20) primary key,Name varchar(20),MobileNumber varchar(20),AadharNumber varchar(20),Address varchar(20),Pincode varchar(20),Amount varchar(20),Year varchar(20),Rate varchar(20),Monthly_Payment varchar(20),Total_Payment varchar(20))')</p><p>root = Tk()</p><p>obj = Login(root)</p><p>root.mainloop()</p>Divyahttp://www.blogger.com/profile/00563752234033470586noreply@blogger.com0tag:blogger.com,1999:blog-2105455976004749882.post-79976160664357567172023-09-26T09:30:00.003+05:302023-09-26T09:30:00.139+05:30Watermark on images<p>import cv2</p><p>import numpy as np</p><p>import glob</p><p>import os</p><p>from numpy._distributor_init import filename</p><p>logo = cv2.imread("logo.jpg")</p><p>h_logo, w_logo, _ = logo.shape</p><p>images_path = glob.glob("flowers/*.*")</p><p>print("Adding watermark")</p><p>for img_path in images_path:</p><p> img = cv2.imread(img_path)</p><p> h_img, w_img, _ = img.shape</p><p> center_y = int(h_img / 2)</p><p> center_x = int(w_img / 2)</p><p> top_y = center_y - int(h_logo / 2)</p><p> left_x = center_x - int(w_logo / 2)</p><p> bottom_y = top_y + h_logo</p><p> right_x = left_x + w_logo</p><p> <span> </span> roi = img[top_y:bottom_y, left_x:right_x]</p><p> result = cv2.addWeighted(roi, 1, logo, 0.3, 0)</p><p> img[top_y:bottom_y, left_x:right_x] = result</p><p> filename= os.path.basename(img_path)</p><p> cv2.imwrite("watermarked_images/watermarked_" + filename, img)</p><p>print("Watermark added to all images") </p>Divyahttp://www.blogger.com/profile/00563752234033470586noreply@blogger.com0tag:blogger.com,1999:blog-2105455976004749882.post-41644748218430947172023-09-23T09:30:00.004+05:302023-09-23T09:30:00.143+05:30Document checker<p>import hashlib</p><p>from difflib import SequenceMatcher</p><p>def hash_file(fileName1, fileName2):</p><p><span style="white-space: normal;"><span> </span>h2 = hashlib.sha1()</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>with open(fileName1, "rb") as file:</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>chunk = 0</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>while chunk != b'':</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>chunk = file.read(1024)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>h1.update(chunk)</span></p><p><span style="white-space: normal; white-space: pre;"> </span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>with open(fileName2, "rb") as file:</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>chunk = 0</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>while chunk != b'':</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>chunk = file.read(1024)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>h2.update(chunk)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>return h1.hexdigest(), h2.hexdigest()</span></p><p>msg1, msg2 = hash_file("pd1.pdf ", "pd1.pdf")</p><p>if(msg1 != msg2):</p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>print("These files are not identical")</span></p><p>else:</p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>print("These files are identical")</span></p><div><br /></div>Divyahttp://www.blogger.com/profile/00563752234033470586noreply@blogger.com0tag:blogger.com,1999:blog-2105455976004749882.post-31406129329808414422023-09-17T09:30:00.002+05:302023-09-17T09:30:00.144+05:30Expense Tracker<p>import datetime</p><p>import sqlite3</p><p>from tkcalendar import DateEntry</p><p>from tkinter import *</p><p>import tkinter.messagebox as mb</p><p>import tkinter.ttk as ttk</p><p>connector = sqlite3.connect("Expense Tracker.db")</p><p>cursor = connector.cursor()</p><p>connector.execute(</p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>'CREATE TABLE IF NOT EXISTS ExpenseTracker (ID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, Date DATETIME, Payee TEXT, Description TEXT, Amount FLOAT, ModeOfPayment TEXT)'</span></p><p>)</p><p>connector.commit()</p><p>def list_all_expenses():</p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>global connector, table</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>table.delete(*table.get_children())</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>all_data = connector.execute('SELECT * FROM ExpenseTracker')</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>data = all_data.fetchall()</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>for values in data:</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>table.insert('', END, values=values)</span></p><p>def view_expense_details():</p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>global table</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>global date, payee, desc, amnt, MoP</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>if not table.selection():</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>mb.showerror('No expense selected', 'Please select an expense from the table to view its details')</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>current_selected_expense = table.item(table.focus())</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>values = current_selected_expense['values']</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>expenditure_date = datetime.date(int(values[1][:4]), int(values[1][5:7]), int(values[1][8:]))</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>date.set_date(expenditure_date) ; payee.set(values[2]) ; desc.set(values[3]) ; amnt.set(values[4]) ; MoP.set(values[5])</span></p><p>def clear_fields():</p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>global desc, payee, amnt, MoP, date, table</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>today_date = datetime.datetime.now().date()</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>desc.set('') ; payee.set('') ; amnt.set(0.0) ; MoP.set('Cash'), date.set_date(today_date)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>table.selection_remove(*table.selection())</span></p><p>def remove_expense():</p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>if not table.selection():</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>mb.showerror('No record selected!', 'Please select a record to delete!')</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>return</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>current_selected_expense = table.item(table.focus())</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>values_selected = current_selected_expense['values']</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>surety = mb.askyesno('Are you sure?', f'Are you sure that you want to delete the record of {values_selected[2]}')</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>if surety:</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>connector.execute('DELETE FROM ExpenseTracker WHERE ID=%d' % values_selected[0])</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>connector.commit()</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>list_all_expenses()</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>mb.showinfo('Record deleted successfully!', 'The record you wanted to delete has been deleted successfully')</span></p><p>def remove_all_expenses():</p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>surety = mb.askyesno('Are you sure?', 'Are you sure that you want to delete all the expense items from the database?', icon='warning')</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>if surety:</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>table.delete(*table.get_children())</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>connector.execute('DELETE FROM ExpenseTracker')</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>connector.commit()</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>clear_fields()</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>list_all_expenses()</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>mb.showinfo('All Expenses deleted', 'All the expenses were successfully deleted')</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>else:</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>mb.showinfo('Ok then', 'The task was aborted and no expense was deleted!')</span></p><p>def add_another_expense():</p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>global date, payee, desc, amnt, MoP</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>global connector</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>if not date.get() or not payee.get() or not desc.get() or not amnt.get() or not MoP.get():</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>mb.showerror('Fields empty!', "Please fill all the missing fields before pressing the add button!")</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>else:</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>connector.execute(</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>'INSERT INTO ExpenseTracker (Date, Payee, Description, Amount, ModeOfPayment) VALUES (?, ?, ?, ?, ?)',</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>(date.get_date(), payee.get(), desc.get(), amnt.get(), MoP.get())</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>connector.commit()</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>clear_fields()</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>list_all_expenses()</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>mb.showinfo('Expense added', 'The expense whose details you just entered has been added to the database')</span></p><p>def edit_expense():</p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>global table</span></p><p><br /></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>def edit_existing_expense():</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>global date, amnt, desc, payee, MoP</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>global connector, table</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>current_selected_expense = table.item(table.focus())</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>contents = current_selected_expense['values']</span></p><p><br /></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>connector.execute('UPDATE ExpenseTracker SET Date = ?, Payee = ?, Description = ?, Amount = ?, ModeOfPayment = ? WHERE ID = ?',</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span> (date.get_date(), payee.get(), desc.get(), amnt.get(), MoP.get(), contents[0]))</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>connector.commit()</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>clear_fields()</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>list_all_expenses()</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>mb.showinfo('Data edited', 'We have updated the data and stored in the database as you wanted')</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>edit_btn.destroy()</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>return</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>if not table.selection():</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>mb.showerror('No expense selected!', 'You have not selected any expense in the table for us to edit; please do that!')</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>return</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>view_expense_details()</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>edit_btn = Button(data_entry_frame, text='Edit expense', font=btn_font, width=30,</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span> bg=hlb_btn_bg, command=edit_existing_expense)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>edit_btn.place(x=10, y=395)</span></p><p>def selected_expense_to_words():</p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>global table</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>if not table.selection():</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>mb.showerror('No expense selected!', 'Please select an expense from the table for us to read')</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>return</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>current_selected_expense = table.item(table.focus())</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>values = current_selected_expense['values']</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>message = f'Your expense can be read like: \n"You paid {values[4]} to {values[2]} for {values[3]} on {values[1]} via {values[5]}"'</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>mb.showinfo('Here\'s how to read your expense', message)</span></p><p>def expense_to_words_before_adding():</p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>global date, desc, amnt, payee, MoP</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>if not date or not desc or not amnt or not payee or not MoP:</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>mb.showerror('Incomplete data', 'The data is incomplete, meaning fill all the fields first!')</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>message = f'Your expense can be read like: \n"You paid {amnt.get()} to {payee.get()} for {desc.get()} on {date.get_date()} via {MoP.get()}"'</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>add_question = mb.askyesno('Read your record like: ', f'{message}\n\nShould I add it to the database?')</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>if add_question:</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>add_another_expense()</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>else:</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>mb.showinfo('Ok', 'Please take your time to add this record')</span></p><p>dataentery_frame_bg = 'light blue'</p><p>buttons_frame_bg = 'light blue'</p><p>hlb_btn_bg = 'light pink'</p><p>lbl_font = ('Georgia', 13)</p><p>entry_font = 'Times 13 bold'</p><p>btn_font = ('Gill Sans MT', 13)</p><p>root = Tk()</p><p>root.title('Expense Tracker')</p><p>root.geometry('1200x550')</p><p>root.resizable(0, 0)</p><p>Label(root, text='EXPENSE TRACKER', font=('Noto Sans CJK TC', 15, 'bold'), bg=hlb_btn_bg).pack(side=TOP, fill=X)</p><p>desc = StringVar()</p><p>amnt = DoubleVar()</p><p>payee = StringVar()</p><p>MoP = StringVar(value='Cash')</p><p>data_entry_frame = Frame(root, bg=dataentery_frame_bg)</p><p>data_entry_frame.place(x=0, y=30, relheight=0.95, relwidth=0.25)</p><p>buttons_frame = Frame(root, bg=buttons_frame_bg)</p><p>buttons_frame.place(relx=0.25, rely=0.05, relwidth=0.75, relheight=0.21)</p><p>tree_frame = Frame(root)</p><p>tree_frame.place(relx=0.25, rely=0.26, relwidth=0.75, relheight=0.74)</p><p>Label(data_entry_frame, text='Date (M/DD/YY) :', font=lbl_font, bg=dataentery_frame_bg).place(x=10, y=50)</p><p>date = DateEntry(data_entry_frame, date=datetime.datetime.now().date(), font=entry_font)</p><p>date.place(x=160, y=50)</p><p>Label(data_entry_frame, text='Payee\t :', font=lbl_font, bg=dataentery_frame_bg).place(x=10, y=230)</p><p>Entry(data_entry_frame, font=entry_font, width=31, text=payee).place(x=10, y=260)</p><p>Label(data_entry_frame, text='Description :', font=lbl_font, bg=dataentery_frame_bg).place(x=10, y=100)</p><p>Entry(data_entry_frame, font=entry_font, width=31, text=desc).place(x=10, y=130)</p><p>Label(data_entry_frame, text='Amount\t :', font=lbl_font, bg=dataentery_frame_bg).place(x=10, y=180)</p><p>Entry(data_entry_frame, font=entry_font, width=14, text=amnt).place(x=160, y=180)</p><p>Label(data_entry_frame, text='Mode of Payment:', font=lbl_font, bg=dataentery_frame_bg).place(x=10, y=310)</p><p>dd1 = OptionMenu(data_entry_frame, MoP, *['Cash', 'Cheque', 'Credit Card', 'Debit Card', 'Paytm', 'Google Pay'])</p><p>dd1.place(x=160, y=305) ; dd1.configure(width=10, font=entry_font)</p><p>Button(data_entry_frame, text='Add expense', command=add_another_expense, font=btn_font, width=30,</p><p> bg=hlb_btn_bg).place(x=10, y=395)</p><p>Button(data_entry_frame, text='Convert to words before adding', font=btn_font, width=30, bg=hlb_btn_bg).place(x=10,y=450)</p><p>Button(buttons_frame, text='Delete Expense', font=btn_font, width=25, bg=hlb_btn_bg, command=remove_expense).place(x=30, y=5)</p><p>Button(buttons_frame, text='Clear Fields in DataEntry Frame', font=btn_font, width=25, bg=hlb_btn_bg,</p><p> command=clear_fields).place(x=335, y=5)</p><p>Button(buttons_frame, text='Delete All Expenses', font=btn_font, width=25, bg=hlb_btn_bg, command=remove_all_expenses).place(x=640, y=5)</p><p>Button(buttons_frame, text='View Selected Expense\'s Details', font=btn_font, width=25, bg=hlb_btn_bg,</p><p> command=view_expense_details).place(x=30, y=65)</p><p>Button(buttons_frame, text='Edit Selected Expense', command=edit_expense, font=btn_font, width=25, bg=hlb_btn_bg).place(x=335,y=65)</p><p>Button(buttons_frame, text='Convert Expense to a sentence', font=btn_font, width=25, bg=hlb_btn_bg,</p><p> command=selected_expense_to_words).place(x=640, y=65)</p><p>table = ttk.Treeview(tree_frame, selectmode=BROWSE, columns=('ID', 'Date', 'Payee', 'Description', 'Amount', 'Mode of Payment'))</p><p>X_Scroller = Scrollbar(table, orient=HORIZONTAL, command=table.xview)</p><p>Y_Scroller = Scrollbar(table, orient=VERTICAL, command=table.yview)</p><p>X_Scroller.pack(side=BOTTOM, fill=X)</p><p>Y_Scroller.pack(side=RIGHT, fill=Y)</p><p>table.config(yscrollcommand=Y_Scroller.set, xscrollcommand=X_Scroller.set)</p><p>table.heading('ID', text='S No.', anchor=CENTER)</p><p>table.heading('Date', text='Date', anchor=CENTER)</p><p>table.heading('Payee', text='Payee', anchor=CENTER)</p><p>table.heading('Description', text='Description', anchor=CENTER)</p><p>table.heading('Amount', text='Amount', anchor=CENTER)</p><p>table.heading('Mode of Payment', text='Mode of Payment', anchor=CENTER)</p><p>table.column('#0', width=0, stretch=NO)</p><p>table.column('#1', width=50, stretch=NO)</p><p>table.column('#2', width=95, stretch=NO) #Date column</p><p>table.column('#3', width=150, stretch=NO) # Payee column</p><p>table.column('#4', width=325, stretch=NO) # Title column</p><p>table.column('#5', width=135, stretch=NO) # Amount column</p><p>table.column('#6', width=125, stretch=NO) # Mode of Payment column</p><p>table.place(relx=0, y=0, relheight=1, relwidth=1)</p><p>list_all_expenses()</p><p>root.update()</p><p>root.mainloop()</p>Divyahttp://www.blogger.com/profile/00563752234033470586noreply@blogger.com0tag:blogger.com,1999:blog-2105455976004749882.post-52000481037355285742023-09-06T09:30:00.003+05:302023-09-06T09:30:00.144+05:30Webcam Sketch<p>import cv2</p><p>import numpy as np</p><p>def webcam_sketch(image):</p><p> img_gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)</p><p> img_gray_blur = cv2.GaussianBlur(img_gray, (5,5), 0)</p><p> canny_edges = cv2.Canny(img_gray_blur, 10, 70)</p><p> ret, mask = cv2.threshold(canny_edges, 70, 255, cv2.THRESH_BINARY_INV)</p><p> return mask</p><p>cap = cv2.VideoCapture(0)</p><p>while True:</p><p> ret, frame = cap.read()</p><p> cv2.imshow('Sketch', webcam_sketch(frame))</p><p> if cv2.waitKey(1) == 13: </p><p> break</p><p>cap.release()</p><p>cv2.destroyAllWindows()</p>Divyahttp://www.blogger.com/profile/00563752234033470586noreply@blogger.com0tag:blogger.com,1999:blog-2105455976004749882.post-33766246849787192402023-08-31T09:30:00.003+05:302023-08-31T09:30:00.141+05:30controlling brightness by hand detection<p>import cv2</p><p>import mediapipe as mp</p><p>from math import hypot</p><p>import screen_brightness_control as sbc</p><p>import numpy as np</p><p>mpHands = mp.solutions.hands</p><p>hands = mpHands.Hands(</p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>static_image_mode=False,</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>model_complexity=1,</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>min_detection_confidence=0.75,</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>min_tracking_confidence=0.75,</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>max_num_hands=2)</span></p><p>Draw = mp.solutions.drawing_utils</p><p>cap = cv2.VideoCapture(0)</p><p>while True:</p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>_, frame = cap.read()</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>frame = cv2.flip(frame, 1)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>frameRGB = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>Process = hands.process(frameRGB)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>landmarkList = []</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>if Process.multi_hand_landmarks:</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>for handlm in Process.multi_hand_landmarks:</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>for _id, landmarks in enumerate(handlm.landmark):</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>height, width, color_channels = frame.shape</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>x, y = int(landmarks.x*width), int(landmarks.y*height)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>landmarkList.append([_id, x, y])</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>Draw.draw_landmarks(frame, handlm,</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>mpHands.HAND_CONNECTIONS)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>if landmarkList != []:</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>x_1, y_1 = landmarkList[4][1], landmarkList[4][2]</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>x_2, y_2 = landmarkList[8][1], landmarkList[8][2]</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>cv2.circle(frame, (x_1, y_1), 7, (0, 255, 0), cv2.FILLED)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>cv2.circle(frame, (x_2, y_2), 7, (0, 255, 0), cv2.FILLED)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>cv2.line(frame, (x_1, y_1), (x_2, y_2), (0, 255, 0), 3)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>L = hypot(x_2-x_1, y_2-y_1)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>b_level = np.interp(L, [15, 220], [0, 100])</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>sbc.set_brightness(int(b_level))</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>cv2.imshow('Image', frame)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>if cv2.waitKey(1) & 0xff == ord('q'):</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>break</span></p><div><br /></div>Divyahttp://www.blogger.com/profile/00563752234033470586noreply@blogger.com0tag:blogger.com,1999:blog-2105455976004749882.post-71891090072009682372023-08-26T09:30:00.002+05:302023-08-26T09:30:00.142+05:30Youtube video downloader<p>import tkinter as tk</p><p>from tkinter import *</p><p>from pytube import YouTube</p><p>from tkinter import messagebox, filedialog</p><p>def Widgets():</p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>head_label = Label(root, text="YouTube Video Downloader",</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>padx=15,</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>pady=15,</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>font="SegoeUI 14",</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>bg="palegreen",</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>fg="black")</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>head_label.grid(row=1,</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>column=1,</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>pady=10,</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>padx=5,</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>columnspan=3)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>link_label = Label(root,</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>text="YouTube link :",</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>bg="salmon",</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>pady=5,</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>padx=5)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>link_label.grid(row=2,</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>column=0,</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>pady=5,</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>padx=5)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>root.linkText = Entry(root,</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>width=35,</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>textvariable=video_Link,</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>font="Arial 14")</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>root.linkText.grid(row=2,</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>column=1,</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>pady=5,</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>padx=5,</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>columnspan=2)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>destination_label = Label(root,</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>text="Destination :",</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>bg="salmon",</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>pady=5,</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>padx=9)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>destination_label.grid(row=3,</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>column=0,</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>pady=5,</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>padx=5)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>root.destinationText = Entry(root,</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>width=27,</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>textvariable=download_Path,</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>font="Arial 14")</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>root.destinationText.grid(row=3,</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>column=1,</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>pady=5,</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>padx=5)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>browse_B = Button(root,</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>text="Browse",</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>command=Browse,</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>width=10,</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>bg="bisque",</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>relief=GROOVE)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>browse_B.grid(row=3,</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>column=2,</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>pady=1,</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>padx=1)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>Download_B = Button(root,</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>text="Download Video",</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>command=Download,</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>width=20,</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>bg="thistle1",</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>pady=10,</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>padx=15,</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>relief=GROOVE,</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>font="Georgia, 13")</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>Download_B.grid(row=4,</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>column=1,</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>pady=20,</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>padx=20)</span></p><p>def Browse():</p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>download_Directory = filedialog.askdirectory(</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>initialdir="YOUR DIRECTORY PATH", title="Save Video")</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>download_Path.set(download_Directory)</span></p><p>def Download():</p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>Youtube_link = video_Link.get()</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>download_Folder = download_Path.get()</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>getVideo = YouTube(Youtube_link)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>videoStream = getVideo.streams.first()</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>videoStream.download(download_Folder)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>messagebox.showinfo("SUCCESSFULLY",</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>"DOWNLOADED AND SAVED IN\n"</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>+ download_Folder)</span></p><p>root = tk.Tk()</p><p>root.geometry("520x280")</p><p>root.resizable(False, False)</p><p>root.title("YouTube Video Downloader")</p><p>root.config(background="light blue")</p><p>video_Link = StringVar()</p><p>download_Path = StringVar()</p><p>Widgets()</p><p>root.mainloop()</p><div><br /></div>Divyahttp://www.blogger.com/profile/00563752234033470586noreply@blogger.com0tag:blogger.com,1999:blog-2105455976004749882.post-42999270122618386522023-08-22T09:30:00.003+05:302023-08-22T09:30:00.148+05:30Counting Fingers<p>import cv2</p><p>import mediapipe as mp</p><p>cap = cv2.VideoCapture(0)</p><p>mp_Hands = mp.solutions.hands</p><p>hands = mp_Hands.Hands()</p><p>mpdraw = mp.solutions.drawing_utils</p><p>finger_Coord = [(8, 6), (12, 10), (16, 14), (20, 18)]</p><p>thumb_Coord = (4,2)</p><p>while True:</p><p> success, image = cap.read()</p><p> RGB_image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)</p><p> results = hands.process(RGB_image)</p><p> multiLandMarks = results.multi_hand_landmarks</p><p> if multiLandMarks:</p><p> handList = []</p><p> for handLms in multiLandMarks:</p><p> mpdraw.draw_landmarks(image, handLms, mp_Hands.HAND_CONNECTIONS)</p><p> for idx, lm in enumerate(handLms.landmark):</p><p> h, w, c = image.shape</p><p> cx, cy = int(lm.x * w), int(lm.y * h)</p><p> handList.append((cx, cy))</p><p> for point in handList:</p><p> cv2.circle(image, point, 10, (255, 255, 0), cv2.FILLED)</p><p> upCount = 0</p><p> for coordinate in finger_Coord:</p><p> if handList[coordinate[0]][1] < handList[coordinate[1]][1]:</p><p> upCount += 1</p><p> if handList[thumb_Coord[0]][0] > handList[thumb_Coord[1]][0]:</p><p> upCount += 1</p><p> cv2.putText(image, str(upCount), (150,150), cv2.FONT_HERSHEY_PLAIN, 12, (0,255,0), 12)</p><p><br /></p><p> cv2.imshow("Counting number of fingers", image)</p><p> cv2.waitKey(1)</p>Divyahttp://www.blogger.com/profile/00563752234033470586noreply@blogger.com0tag:blogger.com,1999:blog-2105455976004749882.post-87369239724171339372023-08-12T09:30:00.005+05:302023-08-12T09:30:00.146+05:30sudoku <p>board=[</p><p> [2,3,0,0,7,0,0,0,0],</p><p> [6,0,0,1,9,5,0,0,0],</p><p> [0,9,8,0,0,0,0,6,0],</p><p> [8,0,0,0,6,0,0,0,3],</p><p> [4,0,0,8,0,3,0,0,1],</p><p> [5,0,0,0,2,0,0,0,6],</p><p> [0,6,0,0,0,0,2,8,0],</p><p> [0,0,0,4,1,9,0,0,5],</p><p> [0,0,0,0,9,0,0,8,9]]</p><p>def print_board(bo):</p><p> for i in range(len(bo)):</p><p> if i%3 == 0 and i!=0:</p><p> print("---------------------")</p><p> for j in range(len(bo[0])):</p><p> if j%3 == 0 and j!=0:</p><p> print(" | ", end ="")</p><p> if j==8:</p><p> print(bo[i][j])</p><p> else:</p><p> print(str(bo[i][j]) + " ",end="")</p><p>def find_empty(bo):</p><p> for i in range(len(bo)):</p><p> for j in range(len(bo[0])):</p><p> if bo[i][j] == 0:</p><p> return (i, j)</p><p> return None</p><p>def valid(bo, num, pos):</p><p> for i in range(len(bo[0])):</p><p> if bo[pos[0]][i] == num and pos[1]!= i:</p><p> return False</p><p> for j in range(len(bo)):</p><p> if bo[i][pos[1]] == num and pos[0]!= i:</p><p> return False</p><p> box_x = pos[1]//3</p><p> box_y = pos[0]//3</p><p> for i in range(box_y*3, box_y*3 + 3):</p><p> for j in range(box_x*3, box_x*3 + 3):</p><p> if bo[i][j] == num and (i,j) != pos:</p><p> return False</p><p> return True</p><p>def solve(bo):</p><p> find = find_empty(bo)</p><p> if not find:</p><p> return True</p><p> else:</p><p> row, col = find</p><p> for i in range(1,10):</p><p> if valid(bo, i , (row,col)):</p><p> bo[row][col] = i</p><p> if solve(bo):</p><p> return True</p><p> bo[row][col]=0</p><p> return False</p><p>print_board(board)</p><p>solve(board)</p><p>print("Solving")</p><p>print_board(board)</p><p>print("Solved")</p>Divyahttp://www.blogger.com/profile/00563752234033470586noreply@blogger.com0tag:blogger.com,1999:blog-2105455976004749882.post-91730225953428644602023-08-07T09:30:00.002+05:302023-08-07T09:30:00.133+05:30snowman <p>import turtle</p><p>turtle.speed(2)</p><p>turtle.setup(800, 700)</p><p>turtle.bgcolor("black")</p><p>turtle.penup()</p><p>turtle.goto(0, -320)</p><p>turtle.pendown()</p><p>turtle.color("#c1f8b5")</p><p>turtle.begin_fill()</p><p>turtle.circle(320)</p><p>turtle.end_fill()</p><p>turtle.penup()</p><p>turtle.goto(0, -280)</p><p>turtle.pendown()</p><p>turtle.color("white")</p><p>turtle.begin_fill()</p><p>turtle.circle(110)</p><p>turtle.end_fill()</p><p>turtle.penup()</p><p>turtle.goto(0, -110)</p><p>turtle.pendown()</p><p>turtle.begin_fill()</p><p>turtle.circle(90)</p><p>turtle.end_fill()</p><p>turtle.penup()</p><p>turtle.goto(0, 20)</p><p>turtle.pendown()</p><p>turtle.begin_fill()</p><p>turtle.circle(70)</p><p>turtle.end_fill()</p><p>def black_circle():</p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>turtle.color("black")</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>turtle.begin_fill()</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>turtle.circle(10)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>turtle.end_fill()</span></p><p>x = -20</p><p>for i in range(2):</p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>turtle.penup()</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>turtle.goto(x, 110)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>turtle.pendown()</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>black_circle()</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>x = x + 40</span></p><p>y = 0</p><p>for i in range(5):</p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>turtle.penup()</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>turtle.goto(0, y)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>turtle.pendown()</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>black_circle()</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>y = y - 55</span></p><p>turtle.penup()</p><p>turtle.goto(0,70)</p><p>turtle.pendown()</p><p>turtle.color("red")</p><p>turtle.begin_fill()</p><p>turtle.circle(17)</p><p>turtle.end_fill()</p><p>turtle.penup()</p><p>turtle.goto(0,75)</p><p>turtle.pendown()</p><p>turtle.color("white")</p><p>turtle.begin_fill()</p><p>turtle.circle(17)</p><p>turtle.end_fill()</p><p>turtle.penup()</p><p>turtle.goto(75, 0)</p><p>turtle.pendown()</p><p>turtle.color("brown")</p><p>turtle.begin_fill()</p><p>turtle.left(40)</p><p>for i in range(2):</p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>turtle.forward(75)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>turtle.left(90)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>turtle.forward(7)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>turtle.left(90)</span></p><p>turtle.end_fill()</p><p>turtle.penup()</p><p>turtle.goto(115, 38)</p><p>turtle.pendown()</p><p>turtle.begin_fill()</p><p>turtle.left(40)</p><p>for i in range(2):</p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>turtle.forward(25)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>turtle.left(90)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>turtle.forward(5)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>turtle.left(90)</span></p><p>turtle.end_fill()</p><p>turtle.begin_fill()</p><p>turtle.right(100)</p><p>for i in range(2):</p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>turtle.forward(25)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>turtle.left(90)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>turtle.forward(5)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>turtle.left(90)</span></p><p>turtle.end_fill()</p><p>turtle.penup()</p><p>turtle.goto(-130, 50)</p><p>turtle.pendown()</p><p>turtle.begin_fill()</p><p>turtle.right(10)</p><p>for i in range(2):</p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>turtle.forward(75)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>turtle.right(90)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>turtle.forward(7)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>turtle.right(90)</span></p><p>turtle.end_fill()</p><p>turtle.penup()</p><p>turtle.goto(-112, 58)</p><p>turtle.pendown()</p><p>turtle.begin_fill()</p><p>turtle.right(40)</p><p>for i in range(2):</p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>turtle.forward(25)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>turtle.right(90)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>turtle.forward(5)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>turtle.right(90)</span></p><p>turtle.end_fill()</p><p>turtle.begin_fill()</p><p>turtle.right(100)</p><p>turtle.penup()</p><p>turtle.goto(-108, 31)</p><p>turtle.pendown()</p><p>for i in range(2):</p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>turtle.forward(25)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>turtle.right(90)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>turtle.forward(5)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>turtle.right(90)</span></p><p>turtle.end_fill()</p><p>turtle.penup()</p><p>turtle.goto(50, 150)</p><p>turtle.pendown()</p><p>turtle.color("black")</p><p>turtle.begin_fill()</p><p>turtle.right(10)</p><p>turtle.forward(100)</p><p>turtle.right(90)</p><p>turtle.forward(10)</p><p>turtle.right(90)</p><p>turtle.forward(20)</p><p>turtle.left(90)</p><p>turtle.forward(45)</p><p>turtle.right(90)</p><p>turtle.forward(60)</p><p>turtle.right(90)</p><p>turtle.forward(45)</p><p>turtle.left(90)</p><p>turtle.forward(20)</p><p>turtle.right(90)</p><p>turtle.end_fill()</p><p>turtle.hideturtle()</p><div><br /></div>Divyahttp://www.blogger.com/profile/00563752234033470586noreply@blogger.com0tag:blogger.com,1999:blog-2105455976004749882.post-54507704692052892222023-07-31T09:30:00.002+05:302023-07-31T09:30:00.143+05:30Extract Links<p>import requests</p><p>from bs4 import BeautifulSoup</p><p>url = 'https://www.pythonforengineers.in/'</p><p>reqs = requests.get(url)</p><p>soup = BeautifulSoup(reqs.text, 'html.parser')</p><p>urls = []</p><p>for link in soup.find_all('a'):</p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>print(link.get('href'))</span></p><div><br /></div>Divyahttp://www.blogger.com/profile/00563752234033470586noreply@blogger.com0tag:blogger.com,1999:blog-2105455976004749882.post-50488551362637836202023-07-24T09:30:00.003+05:302023-07-24T09:30:00.134+05:30Scraping TV Rating <p>import requests</p><p>from bs4 import BeautifulSoup</p><p>def getdata(url):</p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>r = requests.get(url)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>return r.text</span></p><p>htmldata = getdata("https://barcindia.co.in/data-insights")</p><p>soup = BeautifulSoup(htmldata, 'html.parser')</p><p>data = ''</p><p>for i in soup.find_all('tbody'):</p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>data = data + (i.get_text())</span></p><p>data</p><p>data = ''.join((filter(lambda i: i not in ['\t'], data)))</p><p>print(data)</p><div><br /></div>Divyahttp://www.blogger.com/profile/00563752234033470586noreply@blogger.com0tag:blogger.com,1999:blog-2105455976004749882.post-61842006639161551972023-07-17T09:30:00.003+05:302023-07-17T09:30:00.151+05:30Caller Info<p>import requests</p><p>import pandas as pd</p><p>from bs4 import BeautifulSoup</p><p>def getdata(url):</p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>r=requests.get(url)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>return r.text</span></p><p># Enter your own API key </p><p>api = 'YOUR API KEY'</p><p>number = '9876543210'</p><p>country = 'IN'</p><p># pass Your API, number and country code</p><p>htmldata=getdata('http://apilayer.net/api/validate?access_key='+api+'&number='+number+'&country_code='+country+'&format=1')</p><p>soup = BeautifulSoup(htmldata, 'html.parser')</p><p>print(soup)</p><div><br /></div>Divyahttp://www.blogger.com/profile/00563752234033470586noreply@blogger.com0tag:blogger.com,1999:blog-2105455976004749882.post-81463383205741969622023-07-13T09:30:00.002+05:302023-07-13T09:30:00.146+05:30Digital clock<p>import time</p><p>import datetime as dt</p><p>import turtle</p><p>t = turtle.Turtle()</p><p>t1 = turtle.Turtle()</p><p>s = turtle.Screen()</p><p>s.bgcolor("green")</p><p>sec = dt.datetime.now().second</p><p>min = dt.datetime.now().minute</p><p>hr = dt.datetime.now().hour</p><p>t1.pensize(3)</p><p>t1.color('black')</p><p>t1.penup()</p><p>t1.goto(-20, 0)</p><p>t1.pendown()</p><p>for i in range(2):</p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>t1.forward(200)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>t1.left(90)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>t1.forward(70)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>t1.left(90)</span></p><p>t1.hideturtle()</p><p>while True:</p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>t.hideturtle()</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>t.clear()</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>t.write(str(hr).zfill(2)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>+ ":"+str(min).zfill(2)+":"</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>+ str(sec).zfill(2),</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>font=("Arial Narrow", 35, "bold"))</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>time.sleep(1)</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>sec += 1</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>if sec == 60:</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>sec = 0</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>min += 1</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>if min == 60:</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>min = 0</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>hr += 1</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>if hr == 13:</span></p><p><span style="white-space: normal;"><span style="white-space: pre;"> </span>hr = 1</span></p><div><br /></div>Divyahttp://www.blogger.com/profile/00563752234033470586noreply@blogger.com0tag:blogger.com,1999:blog-2105455976004749882.post-31095372665003338632023-07-09T09:30:00.003+05:302023-07-09T09:30:00.129+05:30openai <p>import openai</p><p>openai.api_key = "your secret api key"</p><p>while True:</p><p> model_engine = "text-davinci-003"</p><p> prompt = input('Enter new prompt: ')</p><p> if 'exit' in prompt or 'quit' in prompt:</p><p> break</p><p> completion = openai.Completion.create(</p><p> engine=model_engine,</p><p> prompt=prompt,</p><p> max_tokens=1024,</p><p> n=1,</p><p> stop=None,</p><p> temperature=0.5,</p><p> )</p><p> response = completion.choices[0].text</p><p> print(response)</p><p><br /></p><p>To get secret api key go to <a href="https://openai.com/api/" rel="noreferrer noopener" style="border: 0px; box-sizing: inherit; color: #409bd4; font-family: inherit; font-size: 24px; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; text-decoration-line: none; transition: all 0.2s linear 0s; vertical-align: baseline;" target="_blank">openai.com/api/</a> and signup</p><p>then login and go to <a href="https://platform.openai.com/" rel="noreferrer noopener" style="border: 0px; box-sizing: inherit; color: #409bd4; font-family: inherit; font-size: 24px; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px; text-decoration-line: none; transition: all 0.2s linear 0s; vertical-align: baseline;" target="_blank">platform.openai.com/</a> </p><p>click on personal and then click on vie api keys and now click on 'create new secret key'.</p>Divyahttp://www.blogger.com/profile/00563752234033470586noreply@blogger.com0tag:blogger.com,1999:blog-2105455976004749882.post-47628440619466877522023-06-30T09:30:00.004+05:302023-06-30T09:30:00.141+05:30Scientific calculator<p>import tkinter as tk</p><p>from math import *</p><p>convert_constant = 1</p><p>inverse_convert_constant = 1</p><p>btn_params = {'padx': 16, 'pady': 1, 'bd': 4, 'fg': 'white', 'bg': 'black', 'font': ('arial', 18),</p><p> 'width': 2, 'height': 2, 'relief': 'flat', 'activebackground': "black"}</p><p>def fsin(arg):</p><p> return sin(arg * convert_constant)</p><p>def fcos(arg):</p><p> return cos(arg * convert_constant)</p><p>def ftan(arg):</p><p> return tan(arg * convert_constant)</p><p>def arcsin(arg):</p><p> return inverse_convert_constant * (asin(arg))</p><p>def arccos(arg):</p><p> return inverse_convert_constant * (acos(arg))</p><p>def arctan(arg):</p><p> return inverse_convert_constant * (atan(arg))</p><p>class Calculator:</p><p> def __init__(self, master):</p><p> self.expression = ""</p><p> self.recall = ""</p><p> self.sum_up = ""</p><p> self.text_input = tk.StringVar()</p><p> self.master = master</p><p> top_frame = tk.Frame(master, width=650, height=10,</p><p> bd=10, relief='flat', bg='gray')</p><p> top_frame.pack(side=tk.TOP)</p><p> bottom_frame = tk.Frame(</p><p> master, width=650, height=470, bd=2, relief='flat', bg='black')</p><p> bottom_frame.pack(side=tk.BOTTOM)</p><p> txt_display = tk.Entry(top_frame, font=('arial', 36), relief='flat', bg='black', fg='white', textvariable=self.text_input, width=60, bd=12, justify='right')</p><p> txt_display.pack()</p><p> self.btn_left_brack = tk.Button(</p><p> bottom_frame, **btn_params, text="(", border=1, command=lambda: self.btn_click('('))</p><p> self.btn_left_brack.grid(row=0, column=0)</p><p> self.btn_right_brack = tk.Button(</p><p> bottom_frame, **btn_params, text=")", command=lambda: self.btn_click(')'))</p><p> self.btn_right_brack.grid(row=0, column=1)</p><p> self.btn_exp = tk.Button(</p><p> bottom_frame, **btn_params, text="exp", command=lambda: self.btn_click('exp('))</p><p> self.btn_exp.grid(row=0, column=2)</p><p> self.btn_pi = tk.Button(</p><p> bottom_frame, **btn_params, text="π", command=lambda: self.btn_click('pi'))</p><p> self.btn_pi.grid(row=0, column=3)</p><p> self.btn_sqrt = tk.Button(</p><p> bottom_frame, **btn_params, text="sqrt", command=lambda: self.btn_click('sqrt('))</p><p> self.btn_sqrt.grid(row=0, column=4)</p><p> self.btn_clear = tk.Button(</p><p> bottom_frame, **btn_params, text="C", command=self.btn_clear_all)</p><p> self.btn_clear.grid(row=0, column=5)</p><p> self.btn_del = tk.Button(</p><p> bottom_frame, **btn_params, text="AC", command=self.btn_clear1)</p><p> self.btn_del.grid(row=0, column=6)</p><p> self.btn_change_sign = tk.Button(</p><p> bottom_frame, **btn_params, text="+/-", command=self.change_signs)</p><p> self.btn_change_sign.grid(row=0, column=7)</p><p> self.btn_div = tk.Button(</p><p> bottom_frame, **btn_params, text="/", command=lambda: self.btn_click('/'))</p><p> self.btn_div.grid(row=0, column=8)</p><p> self.btn_Deg = tk.Button(bottom_frame, **btn_params, activeforeground='gray', text="Deg", command=self.convert_deg)</p><p> self.btn_Deg.grid(row=1, column=0)</p><p> self.btn_Rad = tk.Button(bottom_frame, **btn_params, foreground='white', activeforeground='Gray', text="Rad", command=self.convert_rad)</p><p> self.btn_Rad.grid(row=1, column=1)</p><p> self.cube = tk.Button(bottom_frame, **btn_params, text=u"x\u00B3", command=lambda: self.btn_click('**3'))</p><p> self.cube.grid(row=1, column=2)</p><p> self.btn_abs = tk.Button(</p><p> bottom_frame, **btn_params, text="abs", command=lambda: self.btn_click('abs' + '('))</p><p> self.btn_abs.grid(row=1, column=3)</p><p> self.btn_MC = tk.Button(</p><p> bottom_frame, **btn_params, text="MC", command=self.memory_clear)</p><p> self.btn_MC.grid(row=1, column=4)</p><p> self.btn_7 = tk.Button(bottom_frame, **btn_params, text="7", command=lambda: self.btn_click(7))</p><p> self.btn_7.configure(activebackground="black", bg='black')</p><p> self.btn_7.grid(row=1, column=5)</p><p> self.btn_8 = tk.Button(bottom_frame, **btn_params, text="8", command=lambda: self.btn_click(8))</p><p> self.btn_8.configure(activebackground="black", bg='black')</p><p> self.btn_8.grid(row=1, column=6)</p><p> self.btn_9 = tk.Button(bottom_frame, **btn_params, text="9", command=lambda: self.btn_click(9))</p><p> self.btn_9.configure(activebackground="black", bg='black')</p><p> self.btn_9.grid(row=1, column=7)</p><p> self.btn_mult = tk.Button(bottom_frame, **btn_params, text="x", command=lambda: self.btn_click('*'))</p><p> self.btn_mult.grid(row=1, column=8)</p><p> self.btn_sin = tk.Button(</p><p> bottom_frame, **btn_params, text="sin", command=lambda: self.btn_click('fsin('))</p><p> self.btn_sin.grid(row=2, column=0)</p><p> self.btn_cos = tk.Button(</p><p> bottom_frame, **btn_params, text="cos", command=lambda: self.btn_click('fcos('))</p><p> self.btn_cos.grid(row=2, column=1)</p><p> self.btn_tan = tk.Button(bottom_frame, **btn_params, text="tan", command=lambda: self.btn_click('ftan('))</p><p> self.btn_tan.grid(row=2, column=2)</p><p> self.btn_log = tk.Button(bottom_frame, **btn_params, text="log", command=lambda: self.btn_click('log('))</p><p> self.btn_log.grid(row=2, column=3)</p><p> self.btn_MR = tk.Button(bottom_frame, **btn_params, text="MR", command=self.memory_recall)</p><p> self.btn_MR.grid(row=2, column=4)</p><p> self.btn_4 = tk.Button(bottom_frame, **btn_params, text="4", command=lambda: self.btn_click(4))</p><p> self.btn_4.configure(activebackground="black", bg='black')</p><p> self.btn_4.grid(row=2, column=5)</p><p> self.btn_5 = tk.Button(bottom_frame, **btn_params, text="5", command=lambda: self.btn_click(5))</p><p> self.btn_5.configure(activebackground="black", bg='black')</p><p> self.btn_5.grid(row=2, column=6)</p><p> self.btn_6 = tk.Button(bottom_frame, **btn_params, text="6", command=lambda: self.btn_click(6))</p><p> self.btn_6.configure(activebackground="black", bg='black')</p><p> self.btn_6.grid(row=2, column=7)</p><p> self.btnSub = tk.Button(bottom_frame, **btn_params, text="-", command=lambda: self.btn_click('-'))</p><p> self.btnSub.grid(row=2, column=8)</p><p> self.btn_sin_inverse = tk.Button(bottom_frame, **btn_params, text=u"sin-\u00B9", command=lambda: self.btn_click('arcsin('))</p><p> self.btn_sin_inverse.grid(row=3, column=0)</p><p> self.btn_cos_inverse = tk.Button(bottom_frame, **btn_params, text=u"cos-\u00B9", command=lambda: self.btn_click('arccos('))</p><p> self.btn_cos_inverse.grid(row=3, column=1)</p><p> self.btn_tan_inverse = tk.Button(bottom_frame, **btn_params, text=u"tan-\u00B9", command=lambda: self.btn_click('arctan('))</p><p> self.btn_tan_inverse.grid(row=3, column=2)</p><p> self.btn_ln = tk.Button(bottom_frame, **btn_params, text="ln", command=lambda: self.btn_click('log1p('))</p><p> self.btn_ln.grid(row=3, column=3)</p><p> self.btn_M_plus = tk.Button(bottom_frame, **btn_params, text="M+", command=self.memory_add)</p><p> self.btn_M_plus.grid(row=3, column=4)</p><p> self.btn_1 = tk.Button(bottom_frame, **btn_params, text="1", command=lambda: self.btn_click(1))</p><p> self.btn_1.configure(activebackground="black", bg='black')</p><p> self.btn_1.grid(row=3, column=5)</p><p> self.btn_2 = tk.Button(bottom_frame, **btn_params, text="2", command=lambda: self.btn_click(2))</p><p> self.btn_2.configure(activebackground="black", bg='black')</p><p> self.btn_2.grid(row=3, column=6)</p><p> self.btn_3 = tk.Button(bottom_frame, **btn_params, text="3", command=lambda: self.btn_click(3))</p><p> self.btn_3.configure(activebackground="black", bg='black')</p><p> self.btn_3.grid(row=3, column=7)</p><p> self.btn_add = tk.Button(</p><p> bottom_frame, **btn_params, text="+", command=lambda: self.btn_click('+'))</p><p> self.btn_add.grid(row=3, column=8)</p><p> self.btn_fact = tk.Button(bottom_frame, **btn_params, text="n!", command=lambda: self.btn_click('factorial('))</p><p> self.btn_fact.grid(row=4, column=0)</p><p> self.btn_sqr = tk.Button(bottom_frame, **btn_params, text=u"x\u00B2", command=lambda: self.btn_click('**2'))</p><p> self.btn_sqr.grid(row=4, column=1)</p><p> self.btn_power = tk.Button(bottom_frame, **btn_params, text="x^y", command=lambda: self.btn_click('**'))</p><p> self.btn_power.grid(row=4, column=2)</p><p> self.btn_ans = tk.Button(bottom_frame, **btn_params, text="ans", command=self.answer)</p><p> self.btn_ans.grid(row=4, column=3)</p><p> self.btn_comma = tk.Button(bottom_frame, **btn_params, text=",", command=lambda: self.btn_click(','))</p><p> self.btn_comma.grid(row=4, column=4)</p><p> self.btn_0 = tk.Button(bottom_frame, **btn_params, text="0", command=lambda: self.btn_click(0))</p><p> self.btn_0.configure(activebackground="black", bg='black', width=7, bd=5)</p><p> self.btn_0.grid(row=4, column=5, columnspan=2)</p><p> self.btn_eq = tk.Button(bottom_frame, **btn_params, text="=", command=self.btn_equal)</p><p> self.btn_eq.configure(bg='Gray', activebackground='#009999')</p><p> self.btn_eq.grid(row=4, column=7)</p><p> self.btn_dec = tk.Button(bottom_frame, **btn_params, text=".", command=lambda: self.btn_click('.'))</p><p> self.btn_dec.grid(row=4, column=8)</p><p> def btn_click(self, expression_val):</p><p> if len(self.expression) >= 23:</p><p> self.expression = self.expression</p><p> self.text_input.set(self.expression)</p><p> else:</p><p> self.expression = self.expression + str(expression_val)</p><p> self.text_input.set(self.expression)</p><p> def btn_clear1(self):</p><p> self.expression = self.expression[:-1]</p><p> self.text_input.set(self.expression)</p><p> def change_signs(self):</p><p> self.expression = self.expression + '-'</p><p> self.text_input.set(self.expression) </p><p> def memory_clear(self):</p><p> self.recall = "" </p><p> def memory_add(self):</p><p> self.recall = self.recall + '+' + self.expression </p><p> def answer(self):</p><p> self.answer = self.sum_up</p><p> self.expression = self.expression + self.answer</p><p> self.text_input.set(self.expression)</p><p> def memory_recall(self):</p><p> if self.expression == "":</p><p> self.text_input.set('0' + self.expression + self.recall)</p><p> else:</p><p> self.text_input.set(self.expression + self.recall) </p><p> def convert_deg(self):</p><p> global convert_constant</p><p> global inverse_convert_constant</p><p> convert_constant = pi / 180</p><p> inverse_convert_constant = 180 / pi</p><p> self.btn_Rad["foreground"] = 'white'</p><p> self.btn_Deg["foreground"] = 'RED'</p><p> def convert_rad(self):</p><p> global convert_constant</p><p> global inverse_convert_constant</p><p> convert_constant = 1</p><p> inverse_convert_constant = 1</p><p> self.btn_Rad["foreground"] = 'RED'</p><p> self.btn_Deg["foreground"] = 'white' </p><p> def btn_clear_all(self):</p><p> self.expression = ""</p><p> self.text_input.set("") </p><p> def btn_equal(self):</p><p> self.sum_up = str(eval(self.expression))</p><p> self.text_input.set(self.sum_up)</p><p> self.expression = self.sum_up</p><p>root = tk.Tk()</p><p>b = Calculator(root)</p><p>root.title("Scientific Calculator!")</p><p>root.geometry("650x490+50+50")</p><p>root.resizable(False, False)</p><p>root.mainloop()</p>Divyahttp://www.blogger.com/profile/00563752234033470586noreply@blogger.com0tag:blogger.com,1999:blog-2105455976004749882.post-77204160357117707862023-06-27T09:30:00.005+05:302023-06-27T09:30:00.154+05:30music player<p>import pygame</p><p>from pygame import mixer</p><p>pygame.init()</p><p>mixer.init()</p><p>screen = pygame.display.set_mode((600, 400))</p><p>mixer.music.load("audio.mp3")</p><p>mixer.music.play()</p><p>print("Press 'p' to pause 'r' to resume")</p><p>print("Press 'q' to quit")</p><p>running = True</p><p>while running:</p><p> for event in pygame.event.get():</p><p> if event.type == pygame.QUIT:</p><p> running = False</p><p> if event.type == pygame.KEYDOWN:</p><p> if event.key == pygame.K_p:</p><p> mixer.music.pause()</p><p> if event.key == pygame.K_r:</p><p> mixer.music.unpause()</p><p> if event.key == pygame.K_q:</p><p> running = False</p><p>quit()</p>Divyahttp://www.blogger.com/profile/00563752234033470586noreply@blogger.com0tag:blogger.com,1999:blog-2105455976004749882.post-34498614634467916242023-06-23T09:30:00.003+05:302023-06-23T09:30:00.144+05:30Voice Assistant <p>import pyttsx3</p><p>import speech_recognition as sr</p><p>def take_commands():</p><p> r = sr.Recognizer()</p><p> with sr.Microphone() as source:</p><p> print('Listening')</p><p> r.pause_threshold = 0.7</p><p> audio = r.listen(source)</p><p> try:</p><p> print("Recognizing")</p><p> Query = r.recognize_google(audio)</p><p> print("the query is printed='", Query, "'")</p><p> except Exception as e:</p><p> print(e)</p><p> print("Say that again sir")</p><p> return "None"</p><p> return Query</p><p>def Speak(audio):</p><p> engine = pyttsx3.init()</p><p> engine.say(audio)</p><p> engine.runAndWait()</p><p>if __name__ == '__main__':</p><p> while True:</p><p> command = take_commands()</p><p> if "exit" in command:</p><p> Speak("Sure sir! as your wish, bye")</p><p> break</p><p> if "welcome" in command:</p><p> Speak("hi welcome to python for engineers")</p><p> if "python" in command:</p><p> Speak("a complete solution for python programming")</p>Divyahttp://www.blogger.com/profile/00563752234033470586noreply@blogger.com0tag:blogger.com,1999:blog-2105455976004749882.post-83217021451908736572023-06-17T09:30:00.002+05:302023-06-17T09:30:00.141+05:30Typing Speed Test Application<p>from tkinter import *</p><p>import ctypes</p><p>import random</p><p>import tkinter</p><p>ctypes.windll.shcore.SetProcessDpiAwareness(1)</p><p>storage = Tk()</p><p>storage.title('Typing Speed Test')</p><p>storage.geometry('1400x700')</p><p>storage.option_add("*Label.Font", "consolas 30")</p><p>storage.option_add("*Button.Font", "consolas 30")</p><p>def handlingLabels():</p><p> random_selection = [</p><p> 'Software engineering is the branch of computer science that deals with the design, development, testing, and maintenance of software applications. Software engineers apply engineering principles and knowledge of programming languages to build software solutions for end users.',</p><p> 'A web developer is a programmer who develops World Wide Web applications using a client–server model. The applications typically use HTML, CSS, and JavaScript in the client, and any general-purpose programming language in the server. HTTP is used for communications between client and server.'</p><p> ]</p><p> text = random.choice(random_selection).lower()</p><p> splitPoint = 0</p><p> global nameLabelLeft</p><p> nameLabelLeft = Label(storage, text=text[0:splitPoint], fg='green')</p><p> nameLabelLeft.place(relx=0.5, rely=0.5, anchor=E)</p><p> global nameLabelRight</p><p> nameLabelRight = Label(storage, text=text[splitPoint:])</p><p> nameLabelRight.place(relx=0.5, rely=0.5, anchor=W)</p><p> global currentAlphabetLabel</p><p> currentAlphabetLabel = Label(storage, text=text[splitPoint], fg='grey')</p><p> currentAlphabetLabel.place(relx=0.5, rely=0.6, anchor=N)</p><p> global secondsLeft</p><p> headingLabel = Label(storage, text=f'CopyAssignment - Typing Speed Test', fg='blue')</p><p> headingLabel.place(relx=0.5, rely=0.2, anchor=S)</p><p> secondsLeft = Label(storage, text=f'0 Seconds', fg='red')</p><p> secondsLeft.place(relx=0.5, rely=0.4, anchor=S)</p><p> global writeAble</p><p> writeAble = True</p><p> storage.bind('<Key>', handlekeyPress)</p><p> global secondsPassed</p><p> secondsPassed = 0</p><p> storage.after(60000, stopGame)</p><p> storage.after(1000, timeAddition)</p><p>def stopGame():</p><p> global writeAble</p><p> writeAble = False</p><p> amountWords = len(nameLabelLeft.cget('text').split(' '))</p><p> secondsLeft.destroy()</p><p> currentAlphabetLabel.destroy()</p><p> nameLabelRight.destroy()</p><p> nameLabelLeft.destroy()</p><p> global labelOfResult</p><p> labelOfResult = Label(storage, text=f'Words per Minute (WPM): {amountWords}', fg='black')</p><p> labelOfResult.place(relx=0.5, rely=0.4, anchor=CENTER)</p><p> global showcaseResults</p><p> showcaseResults = Button(storage, text=f'Retry', command=restartGame)</p><p> showcaseResults.place(relx=0.5, rely=0.6, anchor=CENTER)</p><p>def restartGame():</p><p> labelOfResult.destroy()</p><p> showcaseResults.destroy()</p><p> handlingLabels()</p><p>def timeAddition():</p><p> global secondsPassed</p><p> secondsPassed += 1</p><p> secondsLeft.configure(text=f'{secondsPassed} Seconds')</p><p> if writeAble:</p><p> storage.after(1000, timeAddition)</p><p>def handlekeyPress(event=None):</p><p> try:</p><p> if event.char.lower() == nameLabelRight.cget('text')[0].lower():</p><p> nameLabelRight.configure(text=nameLabelRight.cget('text')[1:])</p><p> nameLabelLeft.configure(text=nameLabelLeft.cget('text') + event.char.lower())</p><p> currentAlphabetLabel.configure(text=nameLabelRight.cget('text')[0])</p><p> except tkinter.TclError:</p><p> pass</p><p>handlingLabels()</p><p>storage.mainloop()</p><div><br /></div>Divyahttp://www.blogger.com/profile/00563752234033470586noreply@blogger.com0