da mir ja alle dazu geraten haben das Tutorial zu lesen, habe ich noch mehr gemacht. Ich habe das Vorgeschlagene gelesen und noch weitere, ich hab mir auch noch ne Youtube-Reihe dazu reingezogen. Ich habe versucht alles zu behalten und nicht für mich typisch alles wieder über den Jordan zu schicken. Ich verstehe jetzt eure vorherige Kritik an meinem Code. Ich bin aber immer noch nicht ganz überzeugt meine integer Variablen (Rezept-Variablen) durch eine andere Datenstruktur ab zu ändern.
SO, nun seht den Quellcode, den ich jetzt poste, nicht als fertig oder fast "vorzeigbar" an, das ist nur ein weiterer Zwischenschritt zu meiner für mich perfekten Methode. Zur Zeit kämpfe ich damit ,dass ich wenn ich das Programm aufrufe nur einmal einen Cocktail mixen kann.
PS. Ich weiß das ich mir immer mehrere Probleme gleichzeitig schaffe, indem ich ein Problem nicht behandel sondern direkt ein "neues" schaffe, weil ich mit was neuem anfange, aber ich bin sehr schnell von so etwas genervt. Wenn es selbst beim 5 mal korrigieren immer noch Fehler gibt, macht mich das wütend und ich muss mit was neuem anfangen um zumindest ein bisschen ein Erfolgserlebnis zu haben.
Code: Alles auswählen
import sys
import RPi.GPIO as GPIO
from Tkinter import *
import time
#---------------------------------------------- Ventile zuordnen ----------------------------------------------
oSaft_ventil = 2
grenadine_ventil = 3
zitronensaft_ventil = 4
tequila_ventil = 5
wodka_ventil = 6
blueCoracao_ventil = 17
maracujasaft_ventil =18
ananassaft_ventil = 19
#---------------------------------------------- Initiualisierung der GPIOs ----------------------------------------------
GPIO.setmode(GPIO.BCM)
GPIO.setup(oSaft_ventil,GPIO.OUT)
GPIO.setup(grenadine_ventil,GPIO.OUT)
GPIO.setup(zitronensaft_ventil,GPIO.OUT)
GPIO.setup(tequila_ventil,GPIO.OUT)
GPIO.setup(wodka_ventil,GPIO.OUT)
GPIO.setup(blueCoracao_ventil,GPIO.OUT)
GPIO.setup(maracujasaft_ventil,GPIO.OUT)
GPIO.setup(ananassaft_ventil,GPIO.OUT)
#---------------------------------------------- Ventile schließen ----------------------------------------------
GPIO.output(oSaft_ventil,True)
GPIO.output(grenadine_ventil,True)
GPIO.output(zitronensaft_ventil,True)
GPIO.output(tequila_ventil,True)
GPIO.output(wodka_ventil,True)
GPIO.output(blueCoracao_ventil,True)
GPIO.output(maracujasaft_ventil,True)
GPIO.output(ananassaft_ventil,True)
#---------------------------------------------- Cocktailfinder ----------------------------------------------
def mixen(gewaehlterCocktail):
oSaft = 0
grenadine = 0
zitronensaft = 0
tequila = 0
wodka = 0
blueCoracao = 0
maracujasaft = 0
ananassaft = 0
cocktailliste = open("cocktailliste.txt","r")
for line in cocktailliste:
gefundenerCocktail = line.rstrip()
if gefundenerCocktail == gewaehlterCocktail:
print(gewaehlterCocktail)
for line in cocktailliste:
zutat = line.rstrip()
if zutat == "O-Saft":
for line in cocktailliste:
oSaft = int(line.rstrip())
break
if zutat == "Grenadine":
for line in cocktailliste:
grenadine = int(line.rstrip())
break
if zutat == "Zitronensaft":
for line in cocktailliste:
zitronensaft = int(line.rstrip())
break
if zutat == "Tequila":
for line in cocktailliste:
tequila = int(line.rstrip())
break
if zutat == "Wodka":
for line in cocktailliste:
wodka = int(line.rstrip())
break
if zutat == "Blue Coracao":
for line in cocktailliste:
blueCoracao = int(line.rstrip())
break
if zutat == "Maracujasaft":
for line in cocktailliste:
maracujasaft = int(line.rstrip())
break
if zutat == "Ananassaft":
for line in cocktailliste:
ananassaft = int(line.rstrip())
break
if zutat == "Ende":
break
#---------------------------------------------- Mischfunktion ----------------------------------------------
#---------------------------------------------- Max-Finder ----------------------------------------------
maximum = 0
if maximum < oSaft:
maximum = oSaft
if maximum < grenadine:
maximum = grenadine
if maximum < zitronensaft:
maximum = zitronensaft
if maximum < tequila:
maximum = tequila
if maximum < wodka:
maximum = wodka
if maximum < blueCoracao:
maximum = blueCoracao
if maximum < maracujasaft:
maximum = maracujasaft
if maximum < ananassaft:
maximum = ananassaft
#---------------------------------------------- Ventile öffnen ----------------------------------------------
if oSaft != 0:
GPIO.output(oSaft_ventil,False)
if grenadine != 0:
GPIO.output(grenadine_ventil,False)
if zitronensaft != 0:
GPIO.output(zitronensaft_ventil,False)
if tequila != 0:
GPIO.output(tequila_ventil,False)
if wodka != 0:
GPIO.output(wodka_ventil,False)
if blueCoracao != 0:
GPIO.output(blueCoracao_ventil,False)
if maracujasaft != 0:
GPIO.output(maracujasaft_ventil,False)
if ananassaft != 0:
GPIO.output(ananassaft_ventil,False)
#----------------------------------------------Ventile schließen ----------------------------------------------
for i in range(maximum):
if i == oSaft:
GPIO.output(oSaft_ventil,True)
if i == grenadine:
GPIO.output(grenadine_ventil,True)
if i == zitronensaft:
GPIO.output(zitronensaft_ventil,True)
if i == tequila:
GPIO.output(tequila_ventil,True)
if i == wodka:
GPIO.output(wodka_ventil,True)
if i == blueCoracao:
GPIO.output(blueCoracao_ventil,True)
if i == maracujasaft:
GPIO.output(maracujasaft_ventil,True)
if i == ananassaft:
GPIO.output(ananassaft_ventil,True)
time.sleep(1)
GPIO.cleanup()
#---------------------------------------------- Kontrolle kann geschlöscht werden! ----------------------------------------------
print(" ")
print("So viel Osaft ist drin: %d "%(oSaft))
print("So viel Grenadine ist drin: %d "%(grenadine))
print("So viel Zitronensaft ist drin: %d "%(zitronensaft))
print("So viel Tequila ist drin: %d "%(tequila))
print("So viel Wodka ist drin: %d "%(wodka))
print("So viel Blue Coracao ist drin: %d "%(blueCoracao))
print("So viel Maracujasaft ist drin: %d "%(maracujasaft))
print("So viel Ananassaft ist drin: %d "%(ananassaft))
#---------------------------------------------- Layout ----------------------------------------------
#---------------------------------------------- Funktionen ----------------------------------------------
#---------------------------------------------- Auswaehlen ----------------------------------------------
def choose():
print("auswaehlen")
#---------------------------------------------- Mixen ----------------------------------------------
def mixit():
gewaehlterCocktail = liste.get("active")
mixen(gewaehlterCocktail)
#---------------------------------------------- Fullscreen ----------------------------------------------
def close(event):
top.attributes("-fullscreen", False)
top = Tk()
top.attributes("-fullscreen", True)
top.config(bg="white")
top.bind("<Escape>", close)
#---------------------------------------------- Label ----------------------------------------------
cocktail = Label(top)
cocktail.config(height = 30,width = 50, bg = "red")
cocktail.grid(row = 1 , column =2)
rezept = Label(top)
rezept.config(height = 25, width = 35, bg = "grey")
rezept.grid(row = 1 , column = 3)
#---------------------------------------------- Liste ----------------------------------------------
liste = Listbox(top, height = 17)
liste.config(font=('Times New Roman',20))
liste.grid(row = 1, column = 4)
def wechselalk():
liste.delete(0,50)
liste.insert("end","All in One","Alice Deluxe","Baltic","Black Death","El Dorado","Emerald Dream","Exotic Blue","Festini","Florida Sunrise","Green Eyes","Green Poisen","Grüne Wiese","Happy Hour","Hawaiian Vodka","Knock Out","Mexicano","Pink Pussycat","Screwdriver","Simple Red","Springtime Cooler","Tequila Sunrise")
def wechselalkfrei():
liste.delete(0,50)
liste.insert("end","Alice","Ballerina","Batman Cocktail","Bora Bora","Golden Nugget","Pussy Foot","Yellowjacket","Thoothless Shark")
#---------------------------------------------- Frame ----------------------------------------------
frame1 = Frame(top)
frame1.grid(row = 0, column = 4)
#---------------------------------------------- Radiobutton ----------------------------------------------
anti = Radiobutton(frame1, text="Alkoholfrei",font=('Times New Roman',18), bg = "white", value=0,height = 1, command = wechselalkfrei)
voll = Radiobutton(frame1, text="Alkoholvoll",font=('Times New Roman',18), bg = "white", value=1,height = 1, command = wechselalk)
anti.grid(row = 0, sticky = "w")
voll.grid(row = 1, sticky = "w")
#---------------------------------------------- Scrollbar ----------------------------------------------
scroll = Scrollbar(top, orient = VERTICAL, width = 50)
liste["yscrollcommand"]=scroll.set
scroll["command"]=liste.yview
scroll.grid( row = 1, column = 5, sticky=N+S+E)
#---------------------------------------------- Knopf ----------------------------------------------
knopf = Button(text='Choose',height= 2,width = 10,font=('Times New Roman',20),command=choose)
knopf.grid(row = 1,column = 3, sticky=N+E)
mix = Button(text='Mix it',height= 2,width=10,font=('Times New Roman',18), command=mixit)
mix.grid(row = 1, column = 3, sticky = S+E)
top.mainloop()