Initial commit
This commit is contained in:
commit
891b6a8a07
84
gui.py
Normal file
84
gui.py
Normal file
@ -0,0 +1,84 @@
|
||||
import tkinter as tk
|
||||
from tkinter import ttk
|
||||
|
||||
# Initialize main window
|
||||
root = tk.Tk()
|
||||
root.title("Promille Rechner")
|
||||
root.geometry("400x600")
|
||||
|
||||
geschlecht = tk.DoubleVar(value=0.7)
|
||||
gewicht = tk.DoubleVar(value=75.0)
|
||||
drinks = []
|
||||
alkoholgehalt = tk.StringVar(value="0.000‰")
|
||||
|
||||
def add_drink():
|
||||
ml = float(ml_var.get())
|
||||
percent = float(percent_var.get())
|
||||
if ml and percent:
|
||||
drinks.append([ml,percent])
|
||||
update_drinks_display()
|
||||
ml_var.set("")
|
||||
percent_var.set("")
|
||||
|
||||
def remove_last_drink():
|
||||
if drinks: # if drinks is not empty
|
||||
drinks.pop()
|
||||
update_drinks_display()
|
||||
|
||||
def clear_drinks():
|
||||
drinks = []
|
||||
update_drinks_display()
|
||||
|
||||
def update_drinks_display():
|
||||
drinks_text.config(state=tk.NORMAL)
|
||||
drinks_text.delete(1.0, tk.END)
|
||||
drinks_nums = '\n'.join(f"{drink[0]} ml, {drink[1]}%" for drink in drinks)
|
||||
drinks_text.insert(tk.END, drinks_nums)
|
||||
drinks_text.config(state=tk.DISABLED)
|
||||
|
||||
alkohol_masse = sum([drink[0] * (drink[1]/100) * 0.8 for drink in drinks])
|
||||
promille = alkohol_masse / float(gewicht.get()) * float(geschlecht.get())
|
||||
|
||||
alkoholgehalt.set(f"{round(promille, 3)}‰")
|
||||
|
||||
# Ueberschrift
|
||||
tk.Label(root, text="Promille Rechner", font=("Arial", 14)).pack(pady=5)
|
||||
|
||||
# Geschlecht
|
||||
frame_gender = tk.Frame(root)
|
||||
frame_gender.pack()
|
||||
tk.Radiobutton(frame_gender, text="Männlich", variable=geschlecht, value=0.7).pack(side=tk.LEFT)
|
||||
tk.Radiobutton(frame_gender, text="Weiblich", variable=geschlecht, value=0.6).pack(side=tk.LEFT)
|
||||
tk.Radiobutton(frame_gender, text="Minderjährig", variable=geschlecht, value=0.8).pack(side=tk.LEFT)
|
||||
|
||||
# Gewicht
|
||||
tk.Label(root, text="Gewicht (kg):").pack()
|
||||
tk.Entry(root, textvariable=gewicht).pack()
|
||||
|
||||
# Separator
|
||||
ttk.Separator(root, orient="horizontal").pack(fill="x", pady=5)
|
||||
|
||||
# Drink inputs
|
||||
ml_var = tk.StringVar()
|
||||
percent_var = tk.StringVar()
|
||||
tk.Label(root, text="ml:").pack()
|
||||
tk.Entry(root, textvariable=ml_var).pack()
|
||||
tk.Label(root, text="%:").pack()
|
||||
tk.Entry(root, textvariable=percent_var).pack()
|
||||
tk.Button(root, text="Hinzufügen", command=add_drink).pack()
|
||||
|
||||
# Drinks display
|
||||
tk.Label(root, text="Getraenke").pack()
|
||||
drinks_text = tk.Text(root, height=5, state=tk.DISABLED)
|
||||
drinks_text.pack()
|
||||
|
||||
# Buttons to clear drinks
|
||||
tk.Button(root, text="Letztes entfernen", command=remove_last_drink).pack()
|
||||
tk.Button(root, text="Alle entfernen", command=clear_drinks).pack()
|
||||
|
||||
# Promille text
|
||||
tk.Label(root, text="Dein Promillegehalt").pack()
|
||||
alk_label = tk.Label(root, textvariable=alkoholgehalt).pack()
|
||||
|
||||
root.mainloop()
|
||||
|
31
main.py
Normal file
31
main.py
Normal file
@ -0,0 +1,31 @@
|
||||
print("""
|
||||
WILLKOMMEN ZUM ALKOHOLRECHNER
|
||||
""")
|
||||
|
||||
geschlecht = input("Bist du ein Mann, eine Frau oder ein Kind? (m/f/k) ")
|
||||
while geschlecht not in ['m', 'f', 'k']:
|
||||
geschlecht = input("Bitte gib m, f oder k ein (Mann, Frau oder Kind). ")
|
||||
|
||||
faktor = 0.7 if geschlecht == 'm' else 0.6 if geschlecht == 'f' else 0.8
|
||||
|
||||
gewicht = int(input("Wie viel wiegst du? (in kg) "))
|
||||
ready = False
|
||||
counter = 0
|
||||
drinks = []
|
||||
|
||||
while not ready:
|
||||
counter += 1
|
||||
prozent = float(input(f"Wieviel % Alkoholgehalt hat dein {counter}. Getränk? "))
|
||||
anzahl = int(input(f"Wieviel ml hast du von deinem {counter}. Getränk getrunken? "))
|
||||
fertig = input("Hast du noch etwas anderes getrunken? (j/n) ")
|
||||
drinks.append([anzahl, prozent])
|
||||
|
||||
if fertig != "j":
|
||||
ready = True
|
||||
|
||||
masse = sum([drink[0] * (drink[1]/100) * 0.8 for drink in drinks])
|
||||
|
||||
konzentration = masse / gewicht * faktor
|
||||
|
||||
print(f"Dein Blutalkoholgehalt liegt bei {konzentration:.3f} Promille")
|
||||
|
Loading…
x
Reference in New Issue
Block a user