diff --git a/src/component/board.py b/src/component/board.py index 1a17d30f5988779df2c7095e978f6aa5a9f41f2a..afe96a8a9978e3beb2324b1063213df6b409721a 100644 --- a/src/component/board.py +++ b/src/component/board.py @@ -1,4 +1,5 @@ import PySimpleGUI as sg +import time as t from itertools import cycle from src.windows import board from src.handlers import board as board_handler @@ -24,8 +25,11 @@ def loop(): window = board.build(player_1, player_2, board_data) + start_time = t.time() + counter = 0 while True: - event, _values = window.read() + print("-- read") + event, _values = window.read(timeout=100) if event in (sg.WINDOW_CLOSED, "Exit", "-exit-"): break @@ -38,4 +42,14 @@ def loop(): sg.popup(f"¡Felicitaciones! Ha ganado {player['name']}") 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 diff --git a/src/windows/board.py b/src/windows/board.py index fe1dfeb1bb9c99d4fbadcb5a900fac2d3ab3fed6..a25ab86f3b4b25d88f5668f71324891cd5a8001b 100644 --- a/src/windows/board.py +++ b/src/windows/board.py @@ -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 2: " + player_2["name"], key="-P2-", text_color="white")], [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):