Skip to main content
Python

How to Build Rock, Paper, Scissors Game in Python โ€“ Step-by-Step Tutorial (2025)

Want to make your first Python game project? In this beginner-friendly guide, we'll build a Rock, Paper, Scissors game in Python โ€” first as a command-line app, then upgraded with a beautiful GUI usโ€ฆ

G

gs_admin

Author & Reviewer

Published

May 17, 2025

Read Time

2 min read

article.txt
๐Ÿ“ฐ
Python

Want to make your first Python game project? In this beginner-friendly guide, we'll build a Rock, Paper, Scissors game in Python โ€” first as a command-line app, then upgraded with a beautiful GUI using Tkinter, animations, and sounds!

Rock Paper Scissors game in Python
Rock Paper Scissors game in Python

๐Ÿง  Why Rock, Paper, Scissors?

This project is perfect for beginners โ€” short, fun, and it covers if-else logic, loops, random choices, GUI design, event handling, and sound integration. It's also easy to upgrade into a full app!

๐Ÿ–ฅ๏ธ Part 1: Command-Line Version

Let's first build a simple command-line version of the game.

Requirements: Python 3.x, and any IDE like VS Code, PyCharm, or the built-in IDLE.

python
123456789101112131415161718192021222324252627282930313233343536373839
import random

# Options to choose from
options = ["rock", "paper", "scissors"]

# Rules for who wins
win_conditions = {
    "rock": "scissors",
    "paper": "rock",
    "scissors": "paper"
}

def play_game():
    print("๐ŸŽฎ Welcome to Rock, Paper, Scissors!")

    while True:
        user = input("Choose rock, paper or scissors (or 'q' to quit): ").lower()

        if user == 'q':
            print("๐Ÿ‘‹ Thanks for playing! Goodbye!")
            break

        if user not in options:
            print("โŒ Invalid choice. Please try again.")
            continue

        computer = random.choice(options)

        print(f"\nYou chose: {user}")
        print(f"Computer chose: {computer}")

        if user == computer:
            print("๐Ÿค It's a tie!\n")
        elif win_conditions[user] == computer:
            print("โœ… You win!\n")
        else:
            print("๐Ÿ’ป Computer wins!\n")

play_game()

This handles unlimited rounds, invalid inputs, and clear winning messages.

๐ŸŽจ Part 2: Advanced GUI Version

Now let's upgrade it to a graphical version using Tkinter, animated GIFs, and sound effects! ๐Ÿ”ฅ

Additional requirements:

bash
1
pip install pillow pygame
python
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
import tkinter as tk
from PIL import Image, ImageTk, ImageSequence
import random
import threading
import pygame

# --- INIT PYGAME FOR SOUND ---
pygame.mixer.init()

# --- SOUND PLAYER FUNCTION ---
def play_sound(path):
    threading.Thread(target=lambda: pygame.mixer.Sound(path).play(), daemon=True).start()

# --- ANIMATED GIF FUNCTION ---
def animate_gif(label, path, size=(100, 100)):
    img = Image.open(path)

    # Use LANCZOS resampling for high-quality resizing
    frames = [
        ImageTk.PhotoImage(frame.copy().resize(size, Image.Resampling.LANCZOS))
        for frame in ImageSequence.Iterator(img)
    ]

    def update(index):
        label.configure(image=frames[index])
        label.image = frames[index]  # prevent garbage collection
        root.after(100, update, (index + 1) % len(frames))

    update(0)

# --- GAME CONFIG ---
CHOICES = ["Rock", "Paper", "Scissors"]
EMOJIS = {"Rock": "๐Ÿชจ", "Paper": "๐Ÿ“„", "Scissors": "โœ‚๏ธ"}
WINS_AGAINST = {"Rock": "Scissors", "Paper": "Rock", "Scissors": "Paper"}

user_score = 0
comp_score = 0
round_number = 1

# --- GAME LOGIC ---
def play(choice):
    global user_score, comp_score, round_number

    comp_choice = random.choice(CHOICES)
    user_choice_label.config(text=f"You chose: {choice} {EMOJIS[choice]}")
    comp_choice_label.config(text=f"Computer chose: {comp_choice} {EMOJIS[comp_choice]}")

    if choice == comp_choice:
        result = "๐Ÿ˜‚ It's a Tie!"
        result_color = "#F1C40F"
        play_sound("laugh.mp3")
    elif WINS_AGAINST[choice] == comp_choice:
        user_score += 1
        result = "๐Ÿ† You Win!"
        result_color = "#2ECC71"
        play_sound("win.mp3")
    else:
        comp_score += 1
        result = "๐Ÿ˜ค Computer Wins!"
        result_color = "#E74C3C"
        play_sound("boo.mp3")

    result_label.config(text=result, fg=result_color)
    update_scores()
    history.insert(tk.END, f"๐ŸŽฒ Round {round_number}: You - {choice}, Comp - {comp_choice} โžœ {result}")
    round_number += 1

def reset_game():
    global user_score, comp_score, round_number
    user_score = 0
    comp_score = 0
    round_number = 1
    user_choice_label.config(text="You chose: ")
    comp_choice_label.config(text="Computer chose: ")
    result_label.config(text="")
    history.delete(0, tk.END)
    update_scores()

def update_scores():
    user_score_label.config(text=f"๐Ÿง‘ You: {user_score}")
    comp_score_label.config(text=f"๐Ÿค– Comp: {comp_score}")

# --- GUI SETUP ---
root = tk.Tk()
root.title("๐ŸŽฎ Rock, Paper, Scissors - Animated & Sound Edition")
root.geometry("600x900")
root.config(bg="#FFFBEA")
root.resizable(False, False)

# Title
tk.Label(root, text="๐ŸŒŸ Rock, Paper, Scissors ๐ŸŒŸ", font=("Comic Sans MS", 24, "bold"), bg="#FFFBEA", fg="#FF3CAC").pack(pady=10)

# Avatar Frame
avatar_frame = tk.Frame(root, bg="#FFFBEA")
avatar_frame.pack()

user_avatar_label = tk.Label(avatar_frame, bg="#FFFBEA")
user_avatar_label.grid(row=0, column=0, padx=40)

vs_label = tk.Label(avatar_frame, text="โš”๏ธ", font=("Comic Sans MS", 22), bg="#FFFBEA")
vs_label.grid(row=0, column=1)

comp_avatar_label = tk.Label(avatar_frame, bg="#FFFBEA")
comp_avatar_label.grid(row=0, column=2, padx=40)

# Animate the avatars
animate_gif(user_avatar_label, "player.gif", size=(200, 200))
animate_gif(comp_avatar_label, "computer.gif", size=(200, 200))

# Labels
user_choice_label = tk.Label(root, text="You chose: ", font=("Comic Sans MS", 14), bg="#FFFBEA", fg="#0066FF")
user_choice_label.pack()
comp_choice_label = tk.Label(root, text="Computer chose: ", font=("Comic Sans MS", 14), bg="#FFFBEA", fg="#FF6600")
comp_choice_label.pack()

# Result Label
result_label = tk.Label(root, text="", font=("Comic Sans MS", 18, "bold"), bg="#FFFBEA")
result_label.pack(pady=10)

# Buttons
button_frame = tk.Frame(root, bg="#FFFBEA")
button_frame.pack(pady=10)

tk.Button(button_frame, text="๐Ÿชจ ROCK", font=("Comic Sans MS", 14, "bold"), bg="#00C4FF", fg="white", width=12, command=lambda: play("Rock")).grid(row=0, column=0, padx=10)
tk.Button(button_frame, text="๐Ÿ“„ PAPER", font=("Comic Sans MS", 14, "bold"), bg="#FF9F1C", fg="white", width=12, command=lambda: play("Paper")).grid(row=0, column=1, padx=10)
tk.Button(button_frame, text="โœ‚๏ธ SCISSORS", font=("Comic Sans MS", 14, "bold"), bg="#8E44AD", fg="white", width=14, command=lambda: play("Scissors")).grid(row=0, column=2, padx=10)

# Scoreboard
score_frame = tk.Frame(root, bg="#FFFBEA")
score_frame.pack(pady=10)
user_score_label = tk.Label(score_frame, text="๐Ÿง‘ You: 0", font=("Comic Sans MS", 16, "bold"), bg="#FFFBEA", fg="#0066FF")
user_score_label.grid(row=0, column=0, padx=30)
comp_score_label = tk.Label(score_frame, text="๐Ÿค– Comp: 0", font=("Comic Sans MS", 16, "bold"), bg="#FFFBEA", fg="#FF6600")
comp_score_label.grid(row=0, column=1, padx=30)

# Game History
tk.Label(root, text="๐Ÿ“œ Game History", font=("Comic Sans MS", 16, "bold"), bg="#FFFBEA", fg="#FF3CAC").pack(pady=(10, 5))
history = tk.Listbox(root, width=60, height=6, font=("Comic Sans MS", 10))
history.pack()

# Footer
footer = tk.Frame(root, bg="#FFFBEA")
footer.pack(pady=20)
tk.Button(footer, text="๐Ÿ”„ Reset", font=("Comic Sans MS", 12, "bold"), bg="#2ECC71", fg="white", width=12, command=reset_game).grid(row=0, column=0, padx=10)
tk.Button(footer, text="๐Ÿšช Quit", font=("Comic Sans MS", 12, "bold"), bg="#E74C3C", fg="white", width=12, command=root.quit).grid(row=0, column=1, padx=10)

# Run app
root.mainloop()

๐Ÿ” Key Features in the GUI Version

  • Tkinter creates the window (root = tk.Tk()) and handles labels, buttons, and frames.
  • Pillow (PIL) animates the player and computer avatars with smooth frame switching.
  • Pygame plays fun sound effects when you win, lose, or tie.
  • Button clicks like command=lambda: play("Rock") trigger the play() function.
  • Scoreboard & history update dynamically after every round.
  • Reset clears the score and starts fresh without restarting the app; Quit safely exits.

๐Ÿš€ Bonus Ideas to Make It Even Cooler

  • Add Best of 5 / Best of 10 match logic
  • Show a trophy animation on winning
  • Save game history to a text file
  • Add a "Hardcore Mode" with faster choices

๐Ÿ“ข Final Thoughts

Building a Rock, Paper, Scissors game in Python (both CMD and GUI) is a perfect beginner project. It builds your confidence with basic Python syntax and introduces real-world app development using Tkinter and Pygame. Start with the simple version, then upgrade to the GUI for a truly fun mini-project!

G

About the Author: gs_admin

A senior technical contributor specializing in architectural designs, software optimization, database structures, and developer education. Passionate about writing clean code and sharing engineering knowledge.