-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rock_Paper_Scissor_Game.py
118 lines (91 loc) · 3.05 KB
/
Rock_Paper_Scissor_Game.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import random
from tkinter import *
p = 0
score = 0
def Rock():
global p, score
p = 1
listbox.insert(END, f"{len(listbox.get(0, END)) // 2+1}]Your choice: Rock")
c = random.randint(1, 3)
if c == 1:
listbox.insert(END, "Computer's choice: Rock")
listbox.insert(END, "TIE")
elif c == 3:
listbox.insert(END, "Computer's choice: Scissor")
listbox.insert(END, "You win")
score += 1
elif c == 2:
listbox.insert(END, "Computer's choice: Paper")
listbox.insert(END, "Computer wins")
else:
listbox.insert(END, "INVALID NUMBER")
entry2.delete(0, END)
entry2.insert(0, f"{score} out of {len(listbox.get(0, END)) // 2}")
def Paper():
global p, score
p = 2
listbox.insert(END, f"{len(listbox.get(0, END)) // 2+1}]Your choice: Paper")
c = random.randint(1, 3)
if c == 1:
listbox.insert(END, "Computer's choice: Rock")
listbox.insert(END, "You win")
score += 1
elif c == 3:
listbox.insert(END, "Computer's choice: Scissor")
listbox.insert(END, "Computer wins")
elif c == 2:
listbox.insert(END, "Computer's choice: Paper")
listbox.insert(END, "TIE")
else:
listbox.insert(END, "INVALID NUMBER")
entry2.delete(0, END)
entry2.insert(0, f"{score} out of {len(listbox.get(0, END)) // 2}")
def Scissor():
global p, score
p = 3
listbox.insert(END, f"{len(listbox.get(0, END)) // 2+1}]Your choice: Scissor")
c = random.randint(1, 3)
if c == 1:
listbox.insert(END, "Computer's choice: Rock")
listbox.insert(END, "Computer wins")
elif c == 3:
listbox.insert(END, "Computer's choice: Scissor")
listbox.insert(END, "TIE")
elif c == 2:
listbox.insert(END,"Computer's choice: Paper")
listbox.insert(END, "You win")
score += 1
else:
listbox.insert(END, "INVALID NUMBER")
entry2.delete(0, END)
entry2.insert(0, f"{score} out of {len(listbox.get(0, END)) // 2}")
def playagain():
global score
score = 0
listbox.delete(0, END)
entry2.delete(0, END)
window = Tk()
window.geometry("800x800")
window.config(background="light blue")
label = Label(window, text="ROCK PAPER SCISSORS", font="bold 20")
label.place(x=250, y=100)
label1 = Label(window, text="Choose any one button:")
label1.place(x=100, y=200)
rock = Button(window, text="ROCK", command=Rock)
rock.place(x=100, y=300)
paper = Button(window, text="PAPER", command=Paper)
paper.place(x=100, y=400)
scissor = Button(window, text="SCISSOR", command=Scissor)
scissor.place(x=100, y=500)
scrollbar = Scrollbar(window)
scrollbar.place(x=700, y=400, height=200)
listbox = Listbox(window, yscrollcommand=scrollbar.set)
listbox.place(x=300, y=400, width=400)
scrollbar.config(command=listbox.yview)
score_label = Label(window, text="Your score:")
score_label.place(x=100, y=600)
entry2 = Entry(window)
entry2.place(x=400, y=600)
play_again_button = Button(window, text="PLAY AGAIN", command=playagain)
play_again_button.place(x=100, y=700)
window.mainloop()