-
Notifications
You must be signed in to change notification settings - Fork 1
/
RockPaperScissor.py
82 lines (62 loc) · 2.19 KB
/
RockPaperScissor.py
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
# pip install tkinter
#https://www.learnpython.org/
from tkinter import *
import tkinter.messagebox
import random
root = Tk()
root.title("Rock Paper & Scissors")
root.geometry("600x250")
options = ["rock", "paper", "scissors"]
def Play():
computersTurn = random.choice(options)
playersTurn = clicked.get()
#tkinter.messagebox.showinfo(title="Info!", message="Computers Turn: "+ computersTurn)
#Game Logic
if computersTurn == playersTurn:
result.set(" It's a tie!")
elif playersTurn == "rock":
if computersTurn == "scissors":
result.set("Rock Samshes Scissors, You won")
Player.set(Player.get()+1)
elif computersTurn == "paper":
result.set("Paper covers the rock, You Lost")
Computer.set(Computer.get()+1)
elif playersTurn == "paper":
if computersTurn == "rock":
result.set("Paper covers the rock, You won")
Player.set(Player.get()+1)
elif computersTurn == "scissors":
result.set("scissors cuts the paper, You Lost")
Computer.set(Computer.get()+1)
elif playersTurn == "scissors":
if computersTurn == "paper":
result.set("scissors cuts the paper, You won")
Player.set(Player.get()+1)
elif computersTurn == "rock":
result.set("Rock Smashes scissors, You Lost")
Computer.set(Computer.get()+1)
#GUI
Label(root, text="Tap Play to Start!", font="Courier 20 bold").pack()
# datatype of menu text
clicked = StringVar()
result = StringVar()
Computer = IntVar()
Player = IntVar()
# initial menu text
clicked.set( "Choose Your Option" )
result.set("Select & hit Play")
Computer.set(0)
Player.set(0)
# Create Dropdown menu
drop = OptionMenu( root, clicked , *options )
drop.pack()
#Play Button
Button(root, width=10, text="Play", command=Play).pack(pady=7)
#Displaying the Result
Label(root, textvariable=result).pack(pady=3)
#Scoring Labels
Label(root, text="Computer's Score").pack()
Label(root, textvariable=Computer, font="Courier 15 bold").pack(pady=3)
Label(root, text="Player's Score").pack()
Label(root, textvariable=Player, font="Courier 15 bold").pack(pady=3)
root.mainloop()