Ticker

6/recent/ticker-posts

Advertisement

Rock Paper Scissors game using pytho

Rock Paper Scissors, python projects


Rock paper scissors is popular  a hand game usually played between two people, in which player simultaneously form one of three shapes with an outstretched hand.  Today in this blog I'm going to show you how to create simple  rock paper scissors game using python. You can also implement your own rock paper scissors game by using given source code.  

Source code:

# for imoport usfull library.
from tkinter import *
import random
 



# for creating the GUI window.
gui = Tk()


# create a game Tilte.
gui.resizable(0,0) 
gui.title("Rock Paper Scissors ")

# for creating the background color.
gui.configure(bg = "papaya whip")
# create a Label
Label(gui, text = "Rock-Paper-Scissors", font = "  arial 17 bold", bg = "papaya whip", fg = "navy").place(x = 100, y = 50)

#For creating the screen size. 
# NOTE : please insert the gui.geometry(value) depending upon your windows screen size
gui.geometry("1440x2960")
#create a function to store user action.
user_take = StringVar()

Label(gui, text = " choose Any One From: \nrock, paper or scissors ", font = "sans 15 ", bg = "papaya whip", fg = "red").place(x = 100, y= 300) 
Entry(gui, font = "arial 14", textvariable = user_take,  bg = "gray", fg = "gold").place(x = 120, y = 604)


#for computer choice
com_pick = random.randint(1,3)
if com_pick == 1 :
com_pick = "rock"
elif com_pick == 2 :
com_pick = "paper"
else:
com_pick = "scissors"

# create a function to start the game.

Result = StringVar()

def play():
user_pick = user_take.get()
if user_pick == com_pick :
Result.set("Draw, you both select same")
elif user_pick == "rock" and com_pick == "paper" :
Result.set("You loose!.computer select paper.")
elif user_pick == "rock" and com_pick == "scissors" :
Result.set("you win! computer select scissors.")
elif user_pick == "paper" and com_pick == "scissors" :
Result.set("you loose! computer select scissors.")
elif user_pick == "scissors" and com_pick == "rock":
Result.set("You win!  computer select rock")
elif user_pick == "scissors" and com_pick == "rock":
Result.set("you loose!  computer select rock")
elif user_pick == "scissors" and com_pick == "paper":
Result.set("you win. computer select paper")
else:
Result.set("Invalid Error ! ")
# Create function to reset the game.
def Reset():
Result.set("")
user_take.set("")

#create a function to exit the game.
def Exit():
gui.destroy()
# create a function to define a buttons.
Entry(gui, font = "arial 10 bold", textvariable = Result, bg = "seashell3", fg = "red", width = 31).place(x = 50, y = 1200)

Button(gui, font = "arial 13 bold", text = "PLAY", padx = 5, bg = "gold", fg = "navy",command = play).place(x = 500, y = 900)
Button(gui, font = "arial 12 bold", text = "Reset", padx = 10, bg = "gold", fg = "deep sky blue", command = Reset).place( x = 200, y = 1400)
Button(gui, font = "arial 13 bold",text = "Exit", padx = 5, bg = "gold", fg = "red", command = Exit).place(x = 900, y = 1400)

gui.mainloop()


OUTPUT:




If you get any kind of error in this source code then please let me know in comments  section. I'll try my best to solve your error and if you find this tutorial is hepful for you then please share this article with your friends.  I'll  be back with another stuff soon. So, stay tuned & stay happy.

 






Post a Comment

0 Comments