-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpysimplegui.py
60 lines (54 loc) · 1.88 KB
/
pysimplegui.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
import math
import random
import PySimpleGUI as sg
sg.theme("LightGrey2")
layout = [
[sg.Text("Press Rock, Paper, or Scissors!", key="Main")],
[sg.Text("See how much you can win!", key="Second")],
[sg.Button("Rock"), sg.Button("Paper"), sg.Button("Scissors")]
]
wins = 0
ties = 0
defeats = 0
window = sg.Window("Rock, Paper, Scissors", layout)
botPossible = ["Rock", "Paper", "Scissors"]
while True:
botChoice = botPossible[math.floor(random.random() * 3)]
event, values = window.read()
print(event, values)
if event == sg.WIN_CLOSED:
break
elif event == "Rock":
if botChoice == "Rock":
window["Main"].update("It was a tie!")
ties += 1
elif botChoice == "Scissors":
window["Main"].update("You won!")
wins += 1
else:
window["Main"].update("You lost!")
defeats += 1
window["Second"].update(f"Wins: {wins}; Ties: {ties}; Defeats: {defeats}; Bot selection: {botChoice.lower()}")
elif event == "Paper":
if botChoice == "Rock":
window["Main"].update("You won!")
wins += 1
elif botChoice == "Scissors":
window["Main"].update("You lost!")
defeats += 1
else:
window["Main"].update("It was a tie!")
ties += 1
window["Second"].update(f"Wins: {wins}; Ties: {ties}; Defeats: {defeats}; Bot selection: {botChoice.lower()}")
elif event == "Scissors":
if botChoice == "Rock":
window["Main"].update("You lost!")
defeats += 1
elif botChoice == "Scissors":
window["Main"].update("It was a tie!")
ties += 1
else:
window["Main"].update("You won!")
wins += 1
window["Second"].update(f"Wins: {wins}; Ties: {ties}; Defeats: {defeats}; Bot selection: {botChoice.lower()}")
window.close()