In this tutorial, we will learn How To Make Rock Paper Scissors In Python with the help of example source codes.
What is Rock Paper Scissors In Python?
Rock Paper Scissors is a hand game that started in China. It is usually played by two people, and each player makes one of three shapes with their hands at the same time. “Rock,” “Paper,” and “Scissors” are the names of these shapes.
How To Make Rock Paper Scissors In Python With Source Code
Here are the steps on How To Code Rock Paper Scissors.
Step 1: Import Libraries
First, Import all required libraries for the Rock Paper Scissors.
from tkinter import *
import randomStep 2: Add A Tkinter Form
Next, we will create a screen display of the game and name the screen “Rock, Paper, Scissors Game”.
from tkinter import *
import random
root = Tk()
root.title("Rock, Paper, Scissors Game")
width = 625
height = 600
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
x = (screen_width / 2) - (width / 2)
y = (screen_height / 2) - (height / 2)
root.geometry("%dx%d+%d+%d" % (width, height, x, y))
root.resizable(0, 0)
root.config(bg="white")
if __name__ == '__main__':
root.mainloop()
Step 3: Add Frame For The Two Players
Next, we will add two frames and images like, blank image, paper image, rock image and scissors image for the player and the computer and then label its frame.
from tkinter import *
import random
root = Tk()
root.title("ROCK, PAPER, SCISSOR GAME")
width = 625
height = 600
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
x = (screen_width / 2) - (width / 2)
y = (screen_height / 2) - (height / 2)
root.geometry("%dx%d+%d+%d" % (width, height, x, y))
root.resizable(0, 0)
root.config(bg="white")
# ++++++++++++++++++++IMAGES++++++++++++++++++++++++++
blank_image = PhotoImage(file="resources/blank.png")
rock_player = PhotoImage(file="resources/rock_player.png")
rock_player_ado = rock_player.subsample(3, 3)
paper_player = PhotoImage(file="resources/paper_player.png")
paper_player_ado = paper_player.subsample(3, 3)
scissor_player = PhotoImage(file="resources/scissor_player.png")
scissor_player_ado = scissor_player.subsample(3, 3)
rock_computer = PhotoImage(file="resources/rock_computer.png")
paper_computer = PhotoImage(file="resources/paper_computer.png")
scissor_computer = PhotoImage(file="resources/scissor_computer.png")
# ++++++++++++++++++++LABEL WIDGET++++++++++++++++++++++++++
player_image = Label(root, image=blank_image)
computer_image = Label(root, image=blank_image)
player_label = Label(root, text="PLAYER")
player_label.grid(row=1, column=1)
player_label.config(fg="black", font=('Times New Roman', 12, 'bold'))
computer_label = Label(root, text="COMPUTER")
computer_label.grid(row=1, column=3)
computer_label.config(fg="black", font=('Times New Roman', 12, 'bold'))
status_label = Label(root, text="", font=('Times New Roman', 12))
status_label.config(bg="white", fg="red", font=('Times New Roman', 20, 'bold'))
player_image.grid(row=2, column=1, padx=30, pady=20)
computer_image.grid(row=2, column=3, pady=20)
status_label.grid(row=3, column=2)
if __name__ == '__main__':
root.mainloop()
Step 4: Add Images Buttons, Rock, Paper and Scissor
Now, we will add 3 Images buttons, the rock, paper and scissor buttons.
from tkinter import *
import random
root = Tk()
root.title("ROCK, PAPER, SCISSOR GAME")
width = 625
height = 600
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
x = (screen_width / 2) - (width / 2)
y = (screen_height / 2) - (height / 2)
root.geometry("%dx%d+%d+%d" % (width, height, x, y))
root.resizable(0, 0)
root.config(bg="white")
# ++++++++++++++++++++IMAGES++++++++++++++++++++++++++
blank_image = PhotoImage(file="resources/blank.png")
rock_player = PhotoImage(file="resources/rock_player.png")
rock_player_ado = rock_player.subsample(3, 3)
paper_player = PhotoImage(file="resources/paper_player.png")
paper_player_ado = paper_player.subsample(3, 3)
scissor_player = PhotoImage(file="resources/scissor_player.png")
scissor_player_ado = scissor_player.subsample(3, 3)
rock_computer = PhotoImage(file="resources/rock_computer.png")
paper_computer = PhotoImage(file="resources/paper_computer.png")
scissor_computer = PhotoImage(file="resources/scissor_computer.png")
# ++++++++++++++++++++LABEL WIDGET++++++++++++++++++++++++++
player_image = Label(root, image=blank_image)
computer_image = Label(root, image=blank_image)
player_label = Label(root, text="PLAYER")
player_label.grid(row=1, column=1)
player_label.config(fg="black", font=('Times New Roman', 12, 'bold'))
computer_label = Label(root, text="COMPUTER")
computer_label.grid(row=1, column=3)
computer_label.config(fg="black", font=('Times New Roman', 12, 'bold'))
status_label = Label(root, text="", font=('Times New Roman', 12))
status_label.config(bg="white", fg="red", font=('Times New Roman', 20, 'bold'))
player_image.grid(row=2, column=1, padx=30, pady=20)
computer_image.grid(row=2, column=3, pady=20)
status_label.grid(row=3, column=2)
# ++++++++++++++++++++BUTTON WIDGET++++++++++++++++++++++++++
rock = Button(root, image=rock_player_ado)
paper = Button(root, image=paper_player_ado)
scissor = Button(root, image=scissor_player_ado)
rock.grid(row=4, column=1, pady=30)
paper.grid(row=4, column=2, pady=30)
scissor.grid(row=4, column=3, pady=30)
# ++++++++++++++++++++INITIALIZATION++++++++++++ ++++++++++++++
if __name__ == '__main__':
root.mainloop()
Step 5: Add Events To The Buttons
Lastly, we will add an event to the given 3 buttons. Also, we will add the match process between the player and the computer.
from tkinter import *
import random
root = Tk()
root.title("ROCK, PAPER, SCISSOR GAME")
width = 625
height = 600
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
x = (screen_width / 2) - (width / 2)
y = (screen_height / 2) - (height / 2)
root.geometry("%dx%d+%d+%d" % (width, height, x, y))
root.resizable(0, 0)
root.config(bg="white")
# ++++++++++++++++++++IMAGES++++++++++++++++++++++++++
blank_image = PhotoImage(file="resources/blank.png")
rock_player = PhotoImage(file="resources/rock_player.png")
rock_player_ado = rock_player.subsample(3, 3)
paper_player = PhotoImage(file="resources/paper_player.png")
paper_player_ado = paper_player.subsample(3, 3)
scissor_player = PhotoImage(file="resources/scissor_player.png")
scissor_player_ado = scissor_player.subsample(3, 3)
rock_computer = PhotoImage(file="resources/rock_computer.png")
paper_computer = PhotoImage(file="resources/paper_computer.png")
scissor_computer = PhotoImage(file="resources/scissor_computer.png")
# ++++++++++++++++++++METHODS++++++++++++++++++++++++++
def Rock():
global player_option
player_option = 1
player_image.configure(image=rock_player)
MatchProcess()
def Paper():
global player_option
player_option = 2
player_image.configure(image=paper_player)
MatchProcess()
def Scissor():
global player_option
player_option = 3
player_image.configure(image=scissor_player)
MatchProcess()
def MatchProcess():
computer_option = random.randint(1, 3)
if computer_option == 1:
computer_image.configure(image=rock_computer)
RockCom()
elif computer_option == 2:
computer_image.configure(image=paper_computer)
PaperCom()
elif computer_option == 3:
computer_image.configure(image=scissor_computer)
ScissorCom()
def RockCom():
if player_option == 1:
status_label.config(text="Game Tie")
elif player_option == 2:
status_label.config(text="Player Win")
elif player_option == 3:
status_label.config(text="Computer Win")
def PaperCom():
if player_option == 1:
status_label.config(text="Computer Win")
elif player_option == 2:
status_label.config(text="Game Tie")
elif player_option == 3:
status_label.config(text="Player Win")
def ScissorCom():
if player_option == 1:
status_label.config(text="Player Win")
elif player_option == 2:
status_label.config(text="Computer Win")
elif player_option == 3:
status_label.config(text="Game Tie")
# ++++++++++++++++++++LABEL WIDGET++++++++++++++++++++++++++
player_image = Label(root, image=blank_image)
computer_image = Label(root, image=blank_image)
player_label = Label(root, text="PLAYER")
player_label.grid(row=1, column=1)
player_label.config(fg="black", font=('Times New Roman', 12, 'bold'))
computer_label = Label(root, text="COMPUTER")
computer_label.grid(row=1, column=3)
computer_label.config(fg="black", font=('Times New Roman', 12, 'bold'))
status_label = Label(root, text="", font=('Times New Roman', 12))
status_label.config(bg="white", fg="red", font=('Times New Roman', 20, 'bold'))
player_image.grid(row=2, column=1, padx=30, pady=20)
computer_image.grid(row=2, column=3, pady=20)
status_label.grid(row=3, column=2)
# ++++++++++++++++++++BUTTON WIDGET++++++++++++++++++++++++++
rock = Button(root, image=rock_player_ado, command=Rock)
paper = Button(root, image=paper_player_ado, command=Paper)
scissor = Button(root, image=scissor_player_ado, command=Scissor)
rock.grid(row=4, column=1, pady=30)
paper.grid(row=4, column=2, pady=30)
scissor.grid(row=4, column=3, pady=30)
# ++++++++++++++++++++INITIALIZATION++++++++++++ ++++++++++++++
if __name__ == '__main__':
root.mainloop()
Download Full Source Code!
Visit this site to download the Full Source Code on How To Make Rock Paper Scissors For Free!
Frequently Asked Questions
How does this Python Rock Paper Scissors game work?
You pick rock, paper, or scissors (via on-screen buttons or keyboard keys R, P, S). The computer picks randomly using random.choice(). Standard rules: rock beats scissors, scissors beats paper, paper beats rock. Same picks = tie. The game tracks player wins, computer wins, and ties across rounds in a session. Easy extension for capstone: add a simple ML model that learns the player’s pattern after 10 rounds and starts to beat them, an impressive defense add-on.
What Python version do I need to run this game?
Python 3.8 or newer works. We recommend Python 3.11 or 3.12 because Pygame ships pre-built wheels for those versions (faster pip install, no compilation errors). Python 3.13 may need a slightly older Pygame release because some wheels lag the latest CPython. Verify your version with python –version on Windows or python3 –version on Mac/Linux.
How do I install Pygame for this project?
Run pip install pygame in your terminal (Windows: open Command Prompt, Mac/Linux: open Terminal). On Windows, if pip is not recognized, try python -m pip install pygame instead. On Linux, you may need sudo apt install python3-pygame if pip fails. Verify with python -c “import pygame; print(pygame.version.ver)”.
Can I use this Python game as my BSIT capstone project?
On its own, no, most Philippine BSIT panels expect a full system with users, data, reports, and a real-world problem. A single Pygame game is too narrow for capstone scope. BUT, you can use this game as ONE module inside a larger capstone (e.g. a gamified learning system, a math practice tool for elementary students with this game as the reward layer, or an arcade-style POS for an internet cafe). Pair the game with a Django backend, a database, and analytics for a defensible capstone.
Can I package this game as a standalone .exe to distribute?
Yes, use PyInstaller. Run pip install pyinstaller then pyinstaller –onefile –windowed your_game.py from the project folder. PyInstaller bundles Python and Pygame into a single .exe (Windows) or .app (Mac) that runs without Python installed on the target machine. Include asset files (images, sounds) with –add-data “assets;assets”. Output goes to the dist/ folder.
Where do I get help if the game does not run?
Check the top 3 most common failures: (1) Pygame is not installed correctly, re-run pip install pygame. (2) The game cannot find an asset file (image/sound), make sure you run python from the project folder so relative paths resolve. (3) Wrong Python version, this code expects Python 3.8+; older Python 2.x or 3.6 raises syntax errors. If you still hit a wall, drop a comment on this article with the exact error message, our team monitors comments daily.
Conclusion
We have successfully discussed a step-by-step process on How To Make Rock Paper Scissors In Python, which we learned with the help of examples. I hope this Python Game Tutorial will help you a lot.
