Last active
April 1, 2023 14:07
-
-
Save horstjens/9ce8746fdddf7d3de1c79caa7faf49f7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Animation für jeden Würfel | |
import random | |
import PySimpleGUI as sg | |
animation_ende = {"w1":0, | |
"w2":0, | |
"w3":0, | |
"w4":0, | |
"w5":0, | |
} | |
codes = {1:"\u2680", | |
2:"\u2681", | |
3:"\u2682", | |
4:"\u2683", | |
5:"\u2684", | |
6:"\u2685", | |
} | |
gesperrt = {"w1":False, | |
"w2":False, | |
"w3":False, | |
"w4":False, | |
"w5":False, | |
} | |
bgcolor = sg.theme_button_color_background() | |
color = sg.theme_button_color_text() | |
layout = [ | |
[sg.Button("?", key="w1", font=("System",64)), | |
sg.Button("?", key="w2", font=("System",64)), | |
sg.Button("?", key="w3", font=("System",64)), | |
sg.Button("?", key="w4", font=("System",64)), | |
sg.Button("?", key="w5", font=("System",64)), | |
], | |
[sg.Button("Cancel"), sg.Button("würfeln")], | |
] | |
window = sg.Window("kleines Programm", layout) | |
ms = 0 | |
while True: | |
event, values = window.read(timeout=10) | |
if event in ("Cancel", sg.WIN_CLOSED): | |
break | |
if event == sg.TIMEOUT_EVENT: | |
ms += 10 | |
print(ms) | |
for w in gesperrt.keys(): | |
if gesperrt[w]: | |
continue | |
if ms < animation_ende[w]: | |
zahl = random.randint(1,6) | |
window[w].update(text=f"{codes[zahl]}") | |
if event in gesperrt.keys(): | |
gesperrt[event] = not gesperrt[event] | |
if gesperrt[event]: | |
window[event].update(button_color=("grey", bgcolor)) | |
else: | |
window[event].update(button_color=(color, bgcolor)) | |
if event == "würfeln": | |
for i, w in enumerate(gesperrt.keys()): | |
if gesperrt[w]: | |
continue | |
animation_ende[w] = ms + 3000 + i * 500 | |
window.close() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment