Rock, paper and scissors game with Tkinter python

TKINTER FOR MAKING ROCK, PAPER AND SCCISSORS GAME

YOU ONLY NEED SOME BASICS PYTHON KNOWLEDGE TO MAKE THIS PROGRAM LIKE FOR LOOP, MODULE TKINTER,  MODULE RANDOM, IF AN ELSE STATEMENT.






 from tkinter import *

import random
root = Tk()
root.title("ROCK,PAPER AND SCISSORS GAME")
F = Label(root, text="YOUR CHOICE", padx=10, pady=10)
C=Label(root,text="COMPUTER'S CHOICE:", padx=10, pady=10)
st=Label(root,text="CONCLUSION:")
your_choice = Entry(root)
compchoice = Entry(root)
for i in range(8):
def command(choice):
your_choice.get()
your_choice.delete(0,END)
your_choice.insert(0,str(choice))
def dchoice():
compchoice.get()
compchoice.delete(0,END)
compchoice.insert(0,str(random.choice(["scissors","rock","paper"])))
if your_choice.get().strip().lower() == 'paper' and compchoice.get().strip().lower() == "scissors":
loss = Label(root, text="you loss",padx=10, pady=10,bg='red')
loss.grid(row=10, column=6,columnspan=2)
elif your_choice.get().strip().lower() == "paper" and compchoice.get().strip().lower() == "rock":
win = Label(root, text="you win",padx=10, pady=10)
win.grid(row=10, column=6,columnspan=2)
elif your_choice.get().strip().lower() == "scissors" and compchoice.get().strip().lower() == "rock":
loss = Label(root, text="you loss",padx=10, pady=10,bg='red')
loss.grid(row=10, column=6,columnspan=2)
elif your_choice.get().strip().lower() == "scissors" and compchoice.get().strip().lower() == "paper":
win = Label(root, text="you win",padx=10, pady=10,bg='green')
win.grid(row=10, column=6,columnspan=2)
elif your_choice.get().strip().lower() == "rock" and compchoice.get().strip().lower() == "scissors":
win = Label(root, text="you win",padx=10, pady=10,bg='green')
win.grid(row=10, column=6,columnspan=2)
elif your_choice.get().strip().lower() == "rock" and compchoice.get().strip().lower() == "paper":
loss = Label(root, text="you loss",padx=10, pady=10,bg='red')
loss.grid(row=10, column=6,columnspan=2)
elif your_choice.get().strip().lower() == "rock" and compchoice.get().strip().lower() == "rock":
draw = Label(root, text="draw",padx=10, pady=10,bg='yellow')
draw.grid(row=10, column=6,columnspan=2)
elif your_choice.get().strip().lower() == "scissors" and compchoice.get().strip().lower() == "scissors":
draw = Label(root, text="draw",padx=10, pady=10,bg='yellow')
draw.grid(row=10, column=6,columnspan=2)
elif your_choice.get().strip().lower() == "paper" and compchoice.get().strip().lower() == "paper":
draw = Label(root, text="draw",padx=10, pady=10,bg='yellow')
draw.grid(row=10, column=6,columnspan=2)
bp = Button(root, text="paper", command=lambda:command("paper"))
bs = Button(root, text='scissors', command=lambda:command("scissors"))
br = Button(root, text='rock', command=lambda:command("rock"))
be = Button(root,text="enter",command=dchoice)
F.grid(row=4 ,column=5)
C.grid(row=4,column=6)
your_choice.grid(row=5,column=5)
compchoice.grid(row=5,column=6)
bp.grid(row=6, column=5)
bs.grid(row=7, column=5)
br.grid(row=8, column=5)
be.grid(row=6, column=6)
st.grid(row=10, column=5)
root.mainloop()

Comments

Popular Posts