-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrps.py
More file actions
82 lines (61 loc) · 2.51 KB
/
rps.py
File metadata and controls
82 lines (61 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
from tkinter import *
from random import randint
win = 'YOU WIN!'
lose = 'YOU LOSE!'
tie = 'ITS A DRAW!'
#Creating a random number generator that creates the computer's choice
def numGen():
value = randint(0,2)
return(value)
#Comparing the computer's chouce with the player's choice
def compareWithComputer(playerInt):
compInt = numGen()
if(compInt == 0):
if(playerInt == 0):
return 'computer played rock: ' + tie
elif (playerInt == 1):
return 'computer played rock: ' + win
else:
return 'computer played rock: ' + lose
elif(compInt == 1):
if(playerInt == 0):
return 'computer played paper: ' + lose
elif (playerInt == 1):
return 'computer played paper: ' + tie
else:
return 'computer played paper: ' + win
else:
if(playerInt == 0):
return 'computer played scissors: ' + win
elif (playerInt == 1):
return 'computer played scissors: ' + lose
else:
return 'computer played scissors: ' + tie
#Creating the methods for the different buttons
def selectRock():
responceLbl['text'] = compareWithComputer(0)
def selectPaper():
responceLbl['text'] = compareWithComputer(1)
def selectScissors():
responceLbl['text'] = compareWithComputer(2)
#Creating the GUI using Tkinter
root = Tk()
root.title("Rock Paper Scissors")
root.geometry("450x375")
#Creating variables that hold the icons
rockImg = PhotoImage(file = r"C:\Users\adity\Documents\GitHub\RockPaperScissors\icons\rock.png")
paperImg = PhotoImage(file = r"C:\Users\adity\Documents\GitHub\RockPaperScissors\icons\paper.png")
scissorsImg = PhotoImage(file = r"C:\Users\adity\Documents\GitHub\RockPaperScissors\icons\scissors.png")
titleLbl = Label(root, text='Rock Paper Scissors!', font=('anson', 25), padx=20, pady=10)
promptLbl = Label(root, text='click a button')
rockBtn = Button(root, text=' Rock ', padx=20, pady=7, bg='light blue', command=selectRock, image=rockImg, compound=RIGHT)
paperBtn = Button(root, text=' Paper ' , padx=20, pady=7, bg='light green', command=selectPaper, image=paperImg, compound=RIGHT)
scissorsBtn = Button(root, text='Scissors', padx=25, pady=12, bg='pink', command=selectScissors, image=scissorsImg, compound=RIGHT)
responceLbl = Label(root, font=('roboto', 14), pady=5)
titleLbl.pack()
promptLbl.pack()
rockBtn.pack()
paperBtn.pack()
scissorsBtn.pack()
responceLbl.pack()
root.mainloop()