Skip to content

Instantly share code, notes, and snippets.

@jul
Last active April 22, 2024 13:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jul/985c9176fb449744217f04f2fc19a612 to your computer and use it in GitHub Desktop.
Save jul/985c9176fb449744217f04f2fc19a612 to your computer and use it in GitHub Desktop.
Appli pour faire réviser ma fille les additions
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# WTFPL 2.0 do whatever the freak you want with this code except claiming its yours.
#!/usr/bin/env python3
from random import shuffle
import PySimpleGUI as sg
N=5
M=4
first = True
VICT=0
FAIL=0
pool = []
for x in range(0,10):
for y in range(0,11):
pool+=[(x,y)]
shuffle(pool)
X,Y=pool.pop()
button = sg.Button(u"Kenavo", button_color=("white", "grey"), key = "q", font="Any 25")
status = sg.StatusBar(f"Réussite: {VICT}, autre : {FAIL}", key="s", font='Any 25', justification='center')
text=sg.Text(text = f"{X} + {Y} = ?", font='Any 30' ,background_color="black", metadata=(X+Y, (X,Y)),expand_x=True, key="t", justification='center', visible = True)
matrix = [ [sg.Text("%-2d+ %-2d = ?" % (i,j), size=(10,1), key=(i,j)) for i in range(10) ] for j in range(11) ]
layout = [[button], [text], [ sg.Column( [[sg.Button(f"{N*i+j}", font='Any 18', key=j+i*N, size=(3,2), )] for i in range(M)], justification='center') for j in range(N) ] , [matrix], [ status ]]
#other = sg.Window("matrice de réussite", matrix, font='any 17', finalize = True )
other = window = sg.Window('Addition à deviner', layout, font='any 15', finalize=True)
other[text.metadata[1]].Widget.config(background="black")
while True:
event, values = window.read()
success=False
if event == "q":
window.close()
exit()
if event == text.metadata[0]:
success=True
X,Y = text.metadata[1]
swapped_add = text.metadata[1][::-1]
VICT+=1
other[text.metadata[1]].Widget.config(background=X>Y and "green" or X < Y and "blue" or "grey10")
other[text.metadata[1]].update("%-2d+ %-2d = %2d" % (text.metadata[1][0], text.metadata[1][1], text.metadata[0]),visible=True)
try:
# why ask 5 + 7 when a kid know 7 + 5 ? Are we sadistic ?
swapped_add = text.metadata[1][::-1]
pool.pop(pool.index(swapped_add))
other[text.metadata[1][::-1]].Widget.config(background= X <Y and "green" or X > Y and "blue" or "grey20")
other[text.metadata[1][::-1]].update("%-2d+ %-2d = %2d" % (text.metadata[1][1], text.metadata[1][0], text.metadata[0]),visible=True)
except:
#french elegance of treating edge cases
pass
else:
FAIL+=1
other[text.metadata[1]].Widget.config(background="red")
if success:
try:
X,Y=pool.pop()
window["t"].update(f"{X} + {Y} = ?", visible=True)
text.metadata=(X+Y, (X, Y))
other[text.metadata[1]].Widget.config(background="black")
except:
# on peut plus rien popper de pool, on mange une exception
# on a donc fini :D
window["t"].update(f"Bravo tout est fini", visible=True)
window["s"].update(f"Réussite: {VICT}, autre : {FAIL}", visible=True)
@jul
Copy link
Author

jul commented Apr 15, 2024

jeux
Et voici le résultat :

@jul
Copy link
Author

jul commented Apr 22, 2024

fini
dernière version :D on fait pas faire x + Y quand Y+ X a déjà été fait. On crashe pas à la fin, mais on dit bravo et on met en évidence la diagonale des doubles au cours de l'exercice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment