[go: up one dir, main page]

0% found this document useful (0 votes)
502 views13 pages

Rock, Paper and Scissors Using Python and Tkinter Module: Bachelor of Technology IN Computer Science and Engineering

1) The document describes a project to create a Rock, Paper, Scissors game using Python and the Tkinter module. 2) The game prompts the user to select rock, paper, or scissors and randomly selects the computer's choice. It then determines a winner and displays the result. 3) The source code for the game is included, showing how it uses Tkinter to create the graphical interface and random to generate computer choices. Images are also used to represent the selections.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
502 views13 pages

Rock, Paper and Scissors Using Python and Tkinter Module: Bachelor of Technology IN Computer Science and Engineering

1) The document describes a project to create a Rock, Paper, Scissors game using Python and the Tkinter module. 2) The game prompts the user to select rock, paper, or scissors and randomly selects the computer's choice. It then determines a winner and displays the result. 3) The source code for the game is included, showing how it uses Tkinter to create the graphical interface and random to generate computer choices. Images are also used to represent the selections.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

ROCK, PAPER AND SCISSORS USING PYTHON

AND TKINTER MODULE


Mini project report submitted at the end of fourth semester in partial fulfillment of the
requirement for the award of the degree of

BACHELOR OF TECHNOLOGY
IN
COMPUTER SCIENCE AND ENGINEERING
By
D.DEEKSHA SAI J.ANUSHA
193J1A0547 193J1A0557

Under the esteemed guidance


of

Mr. M. Purna Chandra Rao

Assistant Professor

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING


RAGHU INSTITUTE OF TECHNOLOGY
(Autonomous)
Affiliated to JNTU-Kakinada
Dakamarri (V), Bheemunipatnam (M),
Visakhapatnam – 531162
2021

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

1
RAGHU INSTITUTE OF TECHNOLOGY
(Autonomous)
Affiliated to JNTU-Kakinada
Dakamarri (V), Bheemunipatnam (M),
Visakhapatnam

CERTIFICATE
This is to certify that this project entitled “ROCK,PAPER AND SCISSORS USING

PYTHON AND TKINTER MODULE” done by D.DEEKSHA SAI and J.ANUSHA

bearing Regd. No: 193J1A0547, 193J1A0557 during the academic year 2020-2021 in partial

fulfillment of the requirements for the completion of 2nd year of Bachelor of Technology in

Computer Science And Engineering, under the supervision of Mr. E.Uma Shankar Rao,

(PhD), M.Tech, CSE.

Internal Guide Head of The Department


Mr.M.Purna Chandra Rao, Dr. S.Adinarayana,
Department of CSE, Department of CSE,
Raghu Institute of Technology. Raghu Institute of Technology.

EXTERNAL EXAMINER

2
DECLARATION

This is to certify that this project titled is “ROCK,PAPER AND SCISSORS

USING PYTHON AND TKINTER MODULE” bonafide work done by us, in partial

fulfilment of the requirements for the completion of 2nd year of the degree B.Tech and

submitted to the Department of Computer Science & Engineering, Raghu Institute of

Technology, Dakamarri.

We also declare that this project is a result of our own effort and that has not been

copied from anyone and we have taken only citations from the sources which are

mentioned in the references.

D.DEEKSA SAI J.ANUSHA

PLACE: RIT, Visakhapatnam DATE:

3
ABSTRACT
Rock-paper-scissors is a hand game that is played by two people. The
players count to three in unison and simultaneously "throw” one of
three hand signals that correspond to rock, paper or scissors. The
winner is determined by the rules:
 Rock smashes scissors
 Scissors cuts paper
 Paper covers rock
Rock-paper-scissors is a surprisingly popular game that many people
play seriously. Due to the fact that a tie happens around 1/3 of the
time.
 These shapes are "rock" (a closed fist), "paper" (a flat hand), and
"scissors" (a fist with the index finger and middle finger extended,
forming a V). "Scissors" is identical to the two-fingered V sign (also
indicating "victory" or "peace") except that it is pointed horizontally
instead of being held upright in the air.
Rock paper scissors is often used as a fair choosing method between
two people, similar to coin flipping, drawing straws, or
throwing dice in order to settle a dispute or make an unbiased group
decision. Unlike truly random selection methods, however, rock
paper scissors can be played with a degree of skill by recognizing and
exploiting non-random behavior in opponents.

4
APROACH USED
In this project, python is used as it is advantageous for rock-paper-
scissors game . In our first mini-project, we will build a Python
function that takes as input the string (name) which is one of Rock-
paper-scissors the function then simulates playing a round of Rock-
paper-scissors by generating its own random choice from these
alternatives and then determining the winner using a simple rule
that we will next describe.
While Rock-paper-scissor has a set of ten rules that logically
determine who wins a round of RPS, coding up these rules would
require a number of if/elif/else clauses in this mini-project code. A
simpler method for determining the winner is to assign each of the
three choices a number:
• 1 — rock
• 2 — Spock
• 3 — paper

RESULT
1. Prompt the user to select either Rock, Paper, or Scissors.
2. Instruct the computer to randomly select either Rock, Paper, or
Scissors.
3. Compare the user's choice and the computer's choice.
4. Determine a winner (the user or the computer).
5. Inform the user who the winner is.

5
SOURCE CODE
from tkinter import *

import random

root = Tk()
root.title("Rock, Paper, Scissor Game")
width = 570
height = 520
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="#99ff99")
blank_img=PhotoImage(file="images/blank.png")
player_rock=PhotoImage(file="images/player_rock.png")
sm_player_rock=player_rock.subsample(3, 3)
player_paper=PhotoImage(file="images/player_paper.png")
sm_player_paper=player_paper.subsample(3, 3)
player_scissor=PhotoImage(file="images/player_scissor.png")
sm_player_scissor= player_scissor.subsample(3, 3)

6
com_rock=PhotoImage(file="images/com_rock.png")
com_paper=PhotoImage(file="images/com_paper.png")
com_scissor=PhotoImage(file="images/com_scissor.png")

def Rock():
global player_choice
player_choice = 1
player_img.configure(image=player_rock)
MatchProcess()

def Paper():
global player_choice
player_choice = 2
player_img.configure(image=player_paper)
MatchProcess()

def Scissor():
global player_choice
player_choice = 3
player_img.configure(image=player_scissor)
MatchProcess()

def MatchProcess():
com_choice = random.randint(1,3)
if com_choice == 1:
7
comp_img.configure(image=com_rock)
ComputerRock()
elif com_choice == 2:
comp_img.configure(image=com_paper)
ComputerPaper()

elif com_choice == 3:
comp_img.configure(image=com_scissor)
CompututerScissor()

def ComputerRock():
if player_choice == 1:
lbl_status.config(text="Game Tie")
elif player_choice == 2:
lbl_status.config(text="Player Win")
elif player_choice == 3:
lbl_status.config(text="Computer Win")

def ComputerPaper():
if player_choice == 1:
lbl_status.config(text="Computer Win")
elif player_choice == 2:
lbl_status.config(text="Game Tie")
elif player_choice == 3:
lbl_status.config(text="Player Win")
8
def CompututerScissor():
if player_choice == 1:
lbl_status.config(text="Player Win")
elif player_choice == 2:
lbl_status.config(text="Computer Win")
elif player_choice == 3:
lbl_status.config(text="Game Tie")

def ExitApp():
root.destroy()
exit()

player_img = Label(root,image=blank_img)
comp_img = Label(root,image=blank_img)
lbl_player = Label(root,text="PLAYER")
lbl_player.grid(row=1, column=1)
lbl_player.config(bg="#99ff99")
lbl_computer = Label(root,text="COMPUTER")
lbl_computer.grid(row=1, column=3)
lbl_computer.config(bg="#99ff99")
lbl_status=Label(root, text="", font=('arial', 8))
lbl_status.config(bg="#99ff99")
player_img.grid(row=2,column=1, padx=30, pady=20)

9
comp_img.grid(row=2,column=3, pady=20)
lbl_status.grid(row=3, column=2)

rock = Button(root, image=sm_player_rock, command=Rock)


paper = Button(root, image=sm_player_paper, command=Paper)
scissor = Button(root, image=sm_player_scissor, command=Scissor)
btn_quit = Button(root, text="Quit", command=ExitApp)
rock.grid(row=4,column=1, pady=30)
paper.grid(row=4,column=2, pady=30)
scissor.grid(row=4,column=3, pady=30)
btn_quit.grid(row=5, column=2)

if __name__ == '__main__':
root.mainloop()

10
IMAGES USED

BLANK IMAGE

11
OUTPUT OF THE PROJECT

12
CONCLUSION
We have successfully developed the rock-paper-scissors game using
python. We used Tkinter library for rendering graphics. We use a
random module to generate random choices. We learn how to
create button widget. We also learn how to call the function using
button. In this way, we created a rock-paper-scissors python game.
Rock Paper Scissors has been a hit with all age groups tested.  It is a
classic game that is enhanced through picture animations.  However,
for the future, these images could be programmed to look nicer
rather than showing as a plain figure window.  Also, different
versions of the game could be added so the user could choose which
version they would like to play.  There would be the classic version,
and also the version inspired by The Big Bang Theory: Rock Paper
Scissors Lizard Spock.

13

You might also like