Created
June 17, 2023 11:58
-
-
Save horstjens/3f083786df6c341361c8e74761d046f5 to your computer and use it in GitHub Desktop.
fujojo_tipptrainer
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
import random | |
import PySimpleGUI as sg | |
import matplotlib.pyplot as plt | |
import matplotlib | |
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg | |
def draw_figure(canvas, figure): | |
figure_canvas_agg = FigureCanvasTkAgg( | |
figure, canvas) | |
figure_canvas_agg.draw() | |
figure_canvas_agg.get_tk_widget().pack( | |
side='top', fill='both', expand=1) | |
return figure_canvas_agg | |
fig = matplotlib.figure.Figure( | |
figsize=(5, 4), dpi=100) | |
fig.add_subplot(111).plot(["a","b","c"], | |
[5.6, 2.1, 3.5]) | |
#plt.ylabel('some numbers') | |
# lade wortliste | |
print("bitte warten, ich lade die Wortliste") | |
with open("german.txt") as myfile: | |
wortliste = [word.strip() for word in myfile.readlines()] | |
#print(wortliste) | |
#ALPHABET="abcdefghijklmnopqrstuvwxyzöäüß,.-<#+´^1234567890" | |
layout = [ | |
[sg.Canvas(key="CANVAS")], | |
[sg.Multiline("Hallo", size=(80,5), key="text1", | |
disabled=True, font=("Arial", 18))], | |
[sg.Text("du tippst:")], | |
[sg.Multiline("", size=(80,5), key="text2", | |
disabled=True, font=("Arial", 18), text_color="#0000FF")], | |
[sg.Text("Wie viele Zufallswörter:"), | |
sg.Slider(range=(1,100), orientation="h", key="slider1", | |
default_value=4)], | |
[sg.Button("Generate"),sg.Button("Clear"), sg.Button("Exit")], | |
] | |
window = sg.Window("tipptrainer", layout, return_keyboard_events=True) | |
text2 = "" | |
window.finalize() | |
ddd =draw_figure(window["CANVAS"].TKCanvas, fig) | |
while True: | |
event, value = window.read(timeout=10) | |
if event in ("Exit", sg.WIN_CLOSED): | |
break | |
elif event == "Clear": | |
text2 = "" | |
window["text2"].update(text2) | |
elif event == "Generate": | |
text = [] | |
for i in range(int(value["slider1"])): | |
#wortlänge = random.randint(2, 15) | |
#for j in range(wortlänge): | |
# text += random.choice(ALPHABET) | |
#text += " " | |
text.append(random.choice(wortliste)) | |
print(text) | |
text = " ".join(text) | |
window["text1"].update(text) | |
elif event == sg.TIMEOUT_EVENT: | |
pass | |
else: | |
if event == "BackSpace:22": | |
text2 = text2[:-1] | |
elif "Shift" in event: | |
pass | |
elif "space" in event: | |
text2 += " " | |
elif "comma" in event: | |
text2 += "," | |
elif "question" in event: | |
text2 += "?" | |
elif "odiaeresis" in event: | |
text2 += "ö" | |
elif "adiaeresis" in event: | |
text2 += "ä" | |
elif "udiaeresis" in event: | |
text2 += "ü" | |
elif "Odiaeresis" in event: | |
text2 += "Ö" | |
elif "Adiaeresis" in event: | |
text2 += "Ä" | |
elif "Udiaeresis" in event: | |
text2 += "Ü" | |
elif "ssharp" in event: | |
text2 += "ß" | |
else: | |
text2 += event.split(":")[0] | |
window["text2"].update(text2) | |
window.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment