Hand cricket game in Python using tkinter

we all HAVE played hand cricket in out childhood . Its the game in which two people guess a number (between 1 and 6) and show it to one another by opening fingers .if both guessed it different then the score is obtained by adding both of their guesses and if both guesses same number then it is considered as a wicket.

This the program based on that game.

here is the source code:👇👇👇  



from tkinter import *
import numpy
roor = Tk()
roor.title("hand cricket")
label = Label(roor,text="your choice:")
label2 = Label(roor,text="computer's choice:")
label.grid(row=0, column=0)
label2.grid(row=0, column=2)
urchoice = Entry(roor)
compchoice = Entry(roor)
score = Entry(roor)
be = Button(roor, text="enter", command=lambda : computerdecision()).grid(row=1, column=3)
button1 = Button(roor, text="1", command=lambda: button_add(1)).grid(row=1, column=0)
button2 = Button(roor, text="2", command=lambda: button_add(2)).grid(row=2, column=0)
button3 = Button(roor, text="3", command=lambda: button_add(3)).grid(row=3, column=0)
button4 = Button(roor, text="4", command=lambda: button_add(4)).grid(row=1, column=1)
button5 = Button(roor, text="5", command=lambda: button_add(5)).grid(row=2, column=1)
button6 = Button(roor, text="6", command=lambda: button_add(6)).grid(row=3, column=1)
score.insert(0, 0)
def button_add(number):
urchoice.get()
urchoice.delete(0, END)
urchoice.insert(0, int(number))
def computerdecision():
global fnumber
compchoice.get()
compchoice.delete(0, END)
compchoice.insert(0, int(numpy.random.randint(1, 6 + 1, 1)))
Label(roor, text=f"previous score= {int(score.get())}").grid(row=5, column=5)
if urchoice.get() != compchoice.get():
fnumber = int(urchoice.get()) + int(compchoice.get())
Label(roor, text=f"{int(score.get()) + int(fnumber)}").grid(row=5, column=4)
Label(roor, text=" good choice ", bg="green",font='bold').grid(row=3, column=4)
score.get()
score.delete(0, END)
score.insert(0, fnumber)
elif urchoice.get()==compchoice.get():
Label(roor, text=" that was an out ", bg="red",font='bold').grid(row=3, column=4)
urscore=Button(roor,text="curent score",font='bold')
urscore.grid(row=4, column=3)
Label(roor, text="total score :", font="bold").grid(row=5, column=3)
urchoice.grid(row=0, column=1)
score.grid(row=4, column=4)
compchoice.grid(row=0, column=3)
roor.mainloop()

Comments

Popular Posts