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),bg='#8B8386',fg='White',width=30).pack(pady=10)
l1=Label(root,text="Download Speed :",font=("Arial,bold",15),bg='#E6E6FA')
l1.place(x=10,y=80)
ldspd=Label(root,text="",font=("Arial,bold",15),bg='#E6E6FA',fg='#089927')
ldspd.place(x=180,y=80)
l2=Label(root,text="Upload Speed :",font=("Arial,bold",15),bg='#E6E6FA')
l2.place(x=10,y=130)
luspd=Label(root,text="",font=("Arial,bold",15),bg='#E6E6FA',fg='#089927')
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",font=('Arial,bold',15),bd=5,bg='#8B8386',fg='White',activebackground='#8B8386',activeforeground='White',command=check)
btn.place(x=125,y=190)

root.mainloop()