Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on May 25, 2022. It is now read-only.

Commit a85c140

Browse files
Merge pull request #531 from chandrabosep/master
GUI Rock-Paper-Scissors Game
2 parents a51826a + 56bce7c commit a85c140

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Import Required Library
2+
from tkinter import *
3+
from tkinter import ttk
4+
from random import *
5+
6+
# Create Object
7+
root = Tk()
8+
9+
# Set geometry
10+
root.geometry("500x500")
11+
12+
root.title("Rock-Paper-Scissors-Game")
13+
14+
# List of players
15+
list = ["rock","paper","scissors"]
16+
17+
choose_number = randint(0,2)
18+
print(choose_number) # For testing if it works
19+
20+
label = Label(root,text="Computer ",width = 20,height=4,font=("algerian",15))
21+
label.pack()
22+
23+
def spin():
24+
choose_number = randint(0,2)
25+
label.config(text=list[choose_number])
26+
if user_select.get() == "Rock":
27+
user_select_value = 0
28+
print(user_select_value)
29+
elif user_select.get() == "Paper":
30+
user_select_value = 1
31+
print(user_select_value)
32+
elif user_select.get() == "Scissors":
33+
user_select_value = 2
34+
print(user_select_value)
35+
36+
if user_select_value == 0:
37+
if choose_number == 0:
38+
wl_label.config(text="Tie! - "+" Computer:Bad luck")
39+
elif choose_number == 1:
40+
wl_label.config(text="YOU Loose - "+" Computer: I am better ")
41+
elif choose_number == 2 :
42+
wl_label.config(text="YOU Won - "+" Computer: You won by luck")
43+
44+
elif user_select_value == 1:
45+
if choose_number == 1:
46+
wl_label.config(text="Tie! - "+" Computer: Nice game")
47+
elif choose_number == 0:
48+
wl_label.config(text="YOU Won - "+" Computer: Shit how you are better")
49+
elif choose_number == 2 :
50+
wl_label.config(text="YOU Loose - "+" Computer: booo")
51+
52+
elif user_select_value == 2:
53+
if choose_number == 2:
54+
wl_label.config(text="Tie!")
55+
elif choose_number == 0:
56+
wl_label.config(text="YOU Loose - "+" Computer: I am playing this game since i was born")
57+
elif choose_number == 1 :
58+
wl_label.config(text="YOU Won")
59+
60+
61+
62+
# Adding dropdown box for Rock,Paper,Scissors
63+
user_select = ttk.Combobox(root,value=["Rock","Paper","Scissors"])
64+
user_select.current(0)
65+
user_select.pack()
66+
67+
# Add Labels,Button
68+
wl_label = Label(root,text="",font=("arial",10),width=50,height=4)
69+
wl_label.pack()
70+
71+
button = Button(root,text="Spin!",font=("bell mt",10),command=spin)
72+
button.pack()
73+
74+
root.mainloop()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /