Tuesday, April 30, 2024
Save / Saving file to Drive programatically, using Colab
Sunday, November 12, 2023
Automate Bingo game using Python
189 x 126 86 x 87
https://www.blogger.com/blog/post/edit/preview/705067943936137407/8237077484565746551 is the link to creating Bingo cards. Here, we simulate the game play.
from tkinter import *
from random import shuffle
win = Tk()
win.config(bg="white")
win.title("B C R S Children's Day B I N G O")
scrWidth = win.winfo_screenwidth()
scrHeight = win.winfo_screenheight()
winWidth, winHeight = 1200, 680
x = scrWidth//2 - winWidth//2
y = scrHeight//2 - winHeight//2 - 40
win.geometry("%dx%d+%d+%d" % (winWidth, winHeight, x, y))
ctr = 0
L = [i for i in range(1, 91)]
shuffle(L)
def Next():
global ctr
num = L[ctr] # Next number to call
txt1['state'] = NORMAL
txt2['state'] = NORMAL
if num < 10:
lbl2.config(text=(' ' + str(num)))
else:
lbl2.config(text=(' ' + str(num)))
if num < 10:
txt1.insert(END, ' ' + str(num) + ' ')
else:
txt1.insert(END, str(num) + ' ')
L1 = sorted(L[:ctr+1])
txt2.delete("0.0", END)
for i in range(len(L1)):
if L1[i] < 10:
txt2.insert(END, ' ' + str(L1[i]) + ' ')
else:
txt2.insert(END, str(L1[i]) + ' ')
if ctr < 89:
ctr += 1
txt1['state'] = DISABLED
txt2['state'] = DISABLED
if ctr == 90:
btn1['state'] = DISABLED
pic1 = PhotoImage(file="Bingo.png")
lbl1 = Label(win, image=pic1, border=0)
lbl1.place(x=500, y=545)
lbl2 = Label(win, font=("Verdana", 32, "bold"), bg="yellow", width=3,
relief="raised", borderwidth=3, anchor="w", border=2)
lbl2.place(x=150, y=580)
txt1 = Text(win, font=("Verdana", 26, "bold"), width=47, bg="blue",
fg="white", height=6, undo=False)
txt1.place(x=10, y=10)
txt2 = Text(win, font=("Verdana", 26, "bold"), width=47, bg="green",
fg="white", height=6, undo=False)
txt2.place(x=10, y=280)
pic2 = PhotoImage(file="Bingo Next.png")
btn1 = Button(win, image=pic2, command=Next)
btn1.place(x=950, y=550)
win.mainloop()
Wednesday, November 8, 2023
Testing Internet speed
from tkinter import *
import speedtest
root=Tk()
root.geometry("320x250")
root.resizable(False,False)
root.title("Internet Speed Test")
root.config(bg='#E6E6FA')
Label(root,text="Internet Speed Test",font=("Arial,bold",22),
l1=Label(root,text="Download Speed :",font=("Arial,bold",15),bg='
l1.place(x=10,y=80)
ldspd=Label(root,text="",font=
ldspd.place(x=180,y=80)
l2=Label(root,text="Upload Speed :",font=("Arial,bold",15),bg='
l2.place(x=10,y=130)
luspd=Label(root,text="",font=
luspd.place(x=180,y=130)
def check():
spd=speedtest.Speedtest()
spd.get_servers()
dspd=str(round(spd.download() / (10**6),3)) + " Mbps"
uspd=str(round(spd.upload() / (10**6),3)) + " Mbps"
ldspd.config(text=dspd)
luspd.config(text=uspd)
btn=Button(root,text="Check",
btn.place(x=125,y=190)
root.mainloop()
Sunday, October 15, 2023
Automate SQL Table Creation/Insertion using Python
def createTable():
global fields, table
table = input("Enter table name: ")
s = "CREATE TABLE " + table + "(\n"
while True:
attr = input("Enter attribute: ") # Enter empty string to quit
if attr == '':
break
dtype = input("Enter type: ").upper()
fields[attr] = dtype
s += ' ' + attr + ' ' + dtype + ',\n'
s += ');'
s = s[:-4] + s[-2:]
print(s)
out = open("TempTable.txt", 'w')
out.write(s) # Write CREATE TABLE commands to TempTable.txt
out.close()
def addRecords():
global table, fields
out = open("TempRecords.txt", 'w')
while True:
choice = input("Continue inserting? ") # Enter empty string to quit
if choice == '':
break
rec = "INSERT INTO " + table + " VALUES("
for key in fields.keys():
s = "Enter " + key + " - " + fields[key] + ": "
val = input(s)
dtype = fields[key].upper()[:3]
if dtype != "INT" and dtype != "DEC" and dtype != "BOO":
val = "'" + val + "'"
rec += val + ', '
rec = rec[:-2] + ");\n"
out.write(rec) # Write INSERT INTO commands to TempRecords.txt
out.close()
table, fields = "", {}
while True:
print("1. CREATE TABLE")
print("2. INSERT INTO")
print("0. Exit")
choice = input("Enter choice: ")
if choice == '1':
createTable()
elif choice == '2':
addRecords()
elif choice == '0':
break
else:
print("Wrong choice\n")
Monday, August 28, 2023
Using ChatGPT with Python GUI
# Email: bt25.bcrs@gmail.com Password: Bantuda25New
# Verification Mobile: 9847578833
# https://copyassignment.com/create-your-own-chatgpt-with-python/
import openai
from tkinter import *
win = Tk()
win.geometry("750x450")
win['background'] = '#11A37B'
win.title("Using ChatGPT with Python GUI")
openai.api_key = "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"
model_engine = "text-davinci-003"
def reply(e):
completion = openai.Completion.create(n=1, stop=None,
engine="text-davinci-003", prompt=S1.get(),
max_tokens=1024, temperature=0.5)
response = completion.choices[0].text.strip()
txt.delete("0.0", END)
txt.insert("1.0", response)
S1, S2 = StringVar(), StringVar()
S1.set("")
font1 = ("Verdana", 14, "bold")
font2 = ("Verdana", 24, "bold")
lblHeader = Label(win, text="Hosted by BCRS", font=font2, bg='#11A37B', fg='#FFFFFF')
lblHeader.place(x=280, y=25)
pic = PhotoImage(file="ChatGPT.png")
lblImg = Label(win, image=pic)
lblImg.place(x=40, y=5)
lbl = Label(win, text='Enter prompt', font=font1, bg='#11A37B', fg='#FFFFFF')
lbl.place(x=10, y=130)
ent = Entry(win, textvariable=S1, font=font1, width=40, bg='#11A37B', fg='#FFFFFF')
ent.place(x=180, y=130)
ent.bind('<Return>', reply)
ent.focus()
txt = Text(win, font=font1, width=50, height=10, wrap=WORD, bg='#11A37B', fg='#FFFFFF')
txt.place(x=25, y=180)
win.mainloop()
Use ChatGPT with Python
# API Key created on 28th August, 2023, valid for 3 months
# Email: bt25.bcrs@gmail.com Password: Bantuda25New
# Verification Mobile: 9847578833
# https://copyassignment.com/create-your-own-chatgpt-with-python/
import openai
openai.api_key = "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"
while True:
model_engine = "text-davinci-003"
prompt = input('Enter new prompt: ')
if 'exit' in prompt or 'quit' in prompt:
break
completion = openai.Completion.create(
engine=model_engine, prompt=prompt,
max_tokens=1024, n=1, stop=None,
temperature=0.5,
)
response = completion.choices[0].text
print(response)


