-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRPSTK.py
More file actions
58 lines (50 loc) · 1.55 KB
/
RPSTK.py
File metadata and controls
58 lines (50 loc) · 1.55 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
import tkinter as tk
import random
# Function to play the game
def play_game(user_choice):
# Computer makes a choice
computer_choice = random.choice(["Rock", "Paper", "Scissors"])
# Determine the winner
result = ""
if user_choice == "Rock":
if computer_choice == "Rock":
result = "Draw"
elif computer_choice == "Paper":
result = "Computer wins"
else:
result = "You win"
elif user_choice == "Paper":
if computer_choice == "Rock":
result = "You win"
elif computer_choice == "Paper":
result = "Draw"
else:
result = "Computer wins"
else:
if computer_choice == "Rock":
result = "Computer wins"
elif computer_choice == "Paper":
result = "You win"
else:
result = "Draw"
# Show the result
result_label.config(text=f"Result: {result}")
computer_choice_label.config(text=f"Computer chose: {computer_choice}")
# Create the main window
root = tk.Tk()
root.title("Rock, Paper, Scissors")
# Labels
result_label = tk.Label(root, text="Result: ", font=("Helvetica", 16))
result_label.pack()
computer_choice_label = tk.Label(root, text="Computer chose: ", font=("Helvetica", 16))
computer_choice_label.pack()
# Buttons
buttons = [
("Rock", "Rock"),
("Paper", "Paper"),
("Scissors", "Scissors")
]
for text, choice in buttons:
tk.Button(root, text=text, font=("Helvetica", 16), command=lambda c=choice: play_game(c)).pack()
# Run the main loop
root.mainloop()