Commit b5bc5b15 authored by Fedrico Otaran's avatar Fedrico Otaran
Browse files

Agrego timer usado en la explicación de main loop

parent 756da7f6
import PySimpleGUI as sg import PySimpleGUI as sg
import time as t
from itertools import cycle from itertools import cycle
from src.windows import board from src.windows import board
from src.handlers import board as board_handler from src.handlers import board as board_handler
...@@ -24,8 +25,11 @@ def loop(): ...@@ -24,8 +25,11 @@ def loop():
window = board.build(player_1, player_2, board_data) window = board.build(player_1, player_2, board_data)
start_time = t.time()
counter = 0
while True: while True:
event, _values = window.read() print("-- read")
event, _values = window.read(timeout=100)
if event in (sg.WINDOW_CLOSED, "Exit", "-exit-"): if event in (sg.WINDOW_CLOSED, "Exit", "-exit-"):
break break
...@@ -38,4 +42,14 @@ def loop(): ...@@ -38,4 +42,14 @@ def loop():
sg.popup(f"¡Felicitaciones! Ha ganado {player['name']}") sg.popup(f"¡Felicitaciones! Ha ganado {player['name']}")
break break
counter += 1
window["-SIMPLE_TIMER-"].update(f"{counter // 60:02d}:{counter % 60:02d}")
print(f"-- counter {counter}")
current_time = t.time() - start_time
window["-TIMER-"].update(
f"{round(current_time // 60):02d}:{round(current_time % 60):02d}"
)
window.refresh()
return window return window
...@@ -9,6 +9,23 @@ def build(player_1, player_2, board_data): ...@@ -9,6 +9,23 @@ def build(player_1, player_2, board_data):
[sg.Text("Jugador 1: " + player_1["name"], key="-P1-", text_color="darkblue")], [sg.Text("Jugador 1: " + player_1["name"], key="-P1-", text_color="darkblue")],
[sg.Text("Jugador 2: " + player_2["name"], key="-P2-", text_color="white")], [sg.Text("Jugador 2: " + player_2["name"], key="-P2-", text_color="white")],
[sg.Text("")], [sg.Text("")],
[
sg.Text(
"",
size=(8, 2),
font=("Helvetica", 20),
justification="center",
key="-SIMPLE_TIMER-",
),
sg.Text(
"",
size=(8, 2),
font=("Helvetica", 20),
justification="center",
key="-TIMER-",
),
],
[sg.Button("Next", key="-NEXT-")],
] ]
for y in range(3): for y in range(3):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment