ich habe ein Problem, abgesehen davon, dass ich mir gerade versuche Python im Alleingang in einer Woche beizubringen, bin ich dabei eine Cocktailmaschine zu bauen. Ich habe schon alle Teile beisammen und es funktioniert alles mehr oder minder auch im Einklang, nur bei dem Programmierteil habe ich meine Schwierigkeiten. Ich habe leichtes Verständnis in C++ also ist Python mehr oder minder Neuland, also bitte versteht das wenn ihr meinen sehr sehr aufwendigen Quellcode seht.
Meine Probleme sind die folgenden, ich möchte eine Oberfläche haben, in der man durch die verschiedenen Cocktails scrollen kann und des Weiteren das ein Ladebalken oder sowas in der Art erscheint, damit man nicht einfach alle Cocktails gleichzeitig drücken kann. Außerdem bekomm ich es einfach nicht hin alles smart in einem Algorithmus zu schreiben(aber das ist mir im Endeffekt egal).
Ich hoffe ihr könnt mir weiterhelfen.
Code: Alles auswählen
import sys
import Tkinter
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM) #gleiche Bezeichnung wie rasp
GPIO.setwarnings(False) #keine Fehlermeldung
GPIO.setup(2,GPIO.OUT) #Initiualisierung der GPIOs
GPIO.setup(3,GPIO.OUT)
GPIO.setup(4,GPIO.OUT)
GPIO.setup(5,GPIO.OUT)
GPIO.setup(6,GPIO.OUT)
GPIO.setup(17,GPIO.OUT)
GPIO.setup(18,GPIO.OUT)
GPIO.setup(19,GPIO.OUT)
GPIO.output(2,True) #Zum Start alle GPIOs aus
GPIO.output(3,True)
GPIO.output(4,True)
GPIO.output(5,True)
GPIO.output(6,True)
GPIO.output(17,True)
GPIO.output(18,True)
GPIO.output(19,True)
n = .1 #Sekunden-Masseinheit
i = 0
kanister = {}
for i in range(8): #Kanisterfuellmenge
kanister[i+1] = int(input("Geben sie die Menge des Kanisters an:"))
kanister[i+1] = kanister[i+1]*1000
"""
for i in range(8): #Fehlermeldung
if kanister[i+1]<0:
print"Der Kanister ist leer, bitte auffuellen"
"""
def ausgabe(): #aktuelle Kanisterfuellmenge
for i in range(8):
print(i+1 ,kanister[i+1])
print("")
def allinone(event):
GPIO.output(2,False)
GPIO.output(3,False)
GPIO.output(4,False)
GPIO.output(5,False)
GPIO.output(6,False)
GPIO.output(17,False)
GPIO.output(18,False)
GPIO.output(19,False)
time.sleep(3.75*n)
GPIO.output(2,True)
GPIO.output(3,True)
GPIO.output(4,True)
GPIO.output(5,True)
GPIO.output(6,True)
GPIO.output(17,True)
GPIO.output(18,True)
GPIO.output(19,True)
kanister[1] = kanister[1]-3.75
kanister[2] = kanister[2]-3.75
kanister[3] = kanister[3]-3.75
kanister[4] = kanister[4]-3.75
kanister[5] = kanister[5]-3.75
kanister[6] = kanister[6]-3.75
kanister[7] = kanister[7]-3.75
kanister[8] = kanister[8]-3.75
ausgabe()
def alicedeluxe(event): #Alice Deluxe
GPIO.output(19,False)
GPIO.output(2,False)
GPIO.output(3,False)
GPIO.output(6,False)
time.sleep(4*n)
GPIO.output(3,True)
GPIO.output(6,True)
time.sleep(6*n)
GPIO.output(2,True)
time.sleep(2*n)
GPIO.output(19,True)
kanister[8] = kanister[8]-12
kanister[2] = kanister[2]-10
kanister[5] = kanister[5]-4
kanister[6] = kanister[6]-4
ausgabe()
def baltic(event): #Baltic
GPIO.output(2,False)
GPIO.output(6,False)
GPIO.output(18,False)
GPIO.output(4,False)
GPIO.output(17,False)
time.sleep(2*n)
GPIO.output(4,True)
GPIO.output(17,True)
time.sleep(2*n)
GPIO.output(18,True)
time.sleep(2*n)
GPIO.output(6,True)
time.sleep(9*n)
GPIO.output(2,True)
kanister[1] = kanister[1]-15
kanister[5] = kanister[5]-6
kanister[7] = kanister[7]-4
kanister[5] = kanister[5]-2
kanister[6] = kanister[6]-2
ausgabe()
def blackdeath(event): #Black Death
GPIO.output(2,False)
GPIO.output(4,False)
GPIO.output(5,False)
GPIO.output(17,False)
GPIO.output(3,False)
time.sleep(3*n)
GPIO.output(3,True)
time.sleep(3*n)
GPIO.output(4,True)
GPIO.output(5,True)
GPIO.output(17,True)
time.sleep(4*n)
GPIO.output(2,True)
kanister[1] = kanister[1]-10
kanister[2] = kanister[2]-3
kanister[3] = kanister[3]-6
kanister[4] = kanister[4]-6
kanister[6] = kanister[6]-6
ausgabe()
def eldorado(event): #El Dorado
GPIO.output(5,False)
GPIO.output(4,False)
time.sleep(12*n)
GPIO.output(4,True)
time.sleep(6*n)
GPIO.output(5,True)
kanister[3] = kanister[3]-6
kanister[4] = kanister[4]-6
ausgabe()
def emeralddream(event): #Emerald Dream
GPIO.output(17,False)
GPIO.output(6,False)
GPIO.output(2,False)
time.sleep(4*n)
GPIO.output(17,True)
time.sleep(4*n)
GPIO.output(6,True)
time.sleep(8*n)
GPIO.output(2,True)
kanister[1] = kanister[1]-16
kanister[5] = kanister[5]-8
kanister[6] = kanister[6]-4
ausgabe()
def exoticblue(event): #Exotic Blue
GPIO.output(17,False)
GPIO.output(19,False)
time.sleep(10*n)
GPIO.output(17,True)
time.sleep(8*n)
GPIO.output(19,True)
kanister[6] = kanister[6]-10
kanister[8] = kanister[8]-18
ausgabe()
def festini(event): #Festini
GPIO.output(18,False)
GPIO.output(6,False)
time.sleep(8*n)
GPIO.output(6,True)
time.sleep(12*n)
GPIO.output(18,True)
kanister[5] = kanister[5]-8
kanister[7] = kanister[7]-20
ausgabe()
def floridasunrise(event): #Florida Sunrise
GPIO.output(2,False)
GPIO.output(5,False)
GPIO.output(19,False)
GPIO.output(3,False)
time.sleep(4*n)
GPIO.output(3,True)
time.sleep(4*n)
GPIO.output(2,True)
GPIO.output(5,True)
GPIO.output(19,True)
kanister[1] = kanister[1]-8
kanister[4] = kanister[4]-8
kanister[8] = kanister[8]-8
kanister[2] = kanister[2]-4
ausgabe()
def greeneyes(event): #Green Eyes
GPIO.output(2,False)
GPIO.output(6,False)
GPIO.output(17,False)
time.sleep(5*n)
GPIO.output(6,True)
GPIO.output(17,True)
time.sleep(13*n)
GPIO.output(2,True)
kanister[1] = kanister[1]-18
kanister[5] = kanister[5]-5
kanister[6] = kanister[6]-5
ausgabe()
def greenpoisen(event): #Green Poisen
GPIO.output(17,False)
GPIO.output(4,False)
GPIO.output(5,False)
GPIO.output(18,False)
time.sleep(3*n)
GPIO.output(4,True)
GPIO.output(17,True)
time.sleep(3*n)
GPIO.output(5,True)
time.sleep(9*n)
GPIO.output(18,True)
kanister[6] = kanister[6]-3
kanister[5] = kanister[5]-3
kanister[6] = kanister[6]-6
kanister[7] = kanister[7]-15
ausgabe()
def gruenewiese(event): #Gruene Wiese
GPIO.output(17,False)
GPIO.output(2,False)
time.sleep(9*n)
GPIO.output(17,True)
time.sleep(12*n)
GPIO.output(2,True)
kanister[6] = kanister[6]-9
kanister[1] = kanister[1]-21
ausgabe()
def happyhour(event): #Happy Hour
GPIO.output(2,False)
GPIO.output(5,False)
GPIO.output(4,False)
time.sleep(2*n)
GPIO.output(4,True)
time.sleep(8*n)
GPIO.output(5,True)
time.sleep(5*n)
GPIO.output(2,True)
kanister[1] = kanister[1]-15
kanister[4] = kanister[4]-10
kanister[3] = kanister[3]-2
ausgabe()
def hawaiianvodka(event): #Hawaiian Vodka
GPIO.output(6,False)
GPIO.output(19,False)
GPIO.output(2,False)
GPIO.output(3,False)
GPIO.output(4,False)
time.sleep(4*n)
GPIO.output(4,True)
GPIO.output(3,True)
GPIO.output(2,True)
GPIO.output(19,True)
time.sleep(8*n)
GPIO.output(6,True)
kanister[1] = kanister[1]-15
kanister[4] = kanister[4]-10
kanister[3] = kanister[3]-2
kanister[3] = kanister[3]-2
kanister[3] = kanister[3]-2
ausgabe()
def knockout(event): #Knock Out
GPIO.output(2,False)
GPIO.output(4,False)
GPIO.output(5,False)
time.sleep(7*n)
GPIO.output(2,True)
time.sleep(1*n)
GPIO.output(4,True)
time.sleep(7*n)
GPIO.output(5,True)
kanister[1] = kanister[1]-7
kanister[3] = kanister[3]-8
kanister[4] = kanister[4]-15
ausgabe()
def mexicano(event): #Mexicano
GPIO.output(3,False)
GPIO.output(4,False)
GPIO.output(5,False)
GPIO.output(19,False)
time.sleep(6*n)
GPIO.output(3,True)
GPIO.output(4,True)
GPIO.output(19,True)
time.sleep(6*n)
GPIO.output(5,True)
kanister[2] = kanister[2]-6
kanister[3] = kanister[3]-6
kanister[4] = kanister[4]-12
kanister[8] = kanister[8]-6
ausgabe()
def pinkpussycat(event): #Pink Pussycat
GPIO.output(3,False)
GPIO.output(6,False)
GPIO.output(19,False)
time.sleep(2*n)
GPIO.output(3,True)
time.sleep(9*n)
GPIO.output(6,True)
time.sleep(5*n)
GPIO.output(19,True)
kanister[2] = kanister[2]-2
kanister[5] = kanister[5]-11
kanister[8] = kanister[8]-16
ausgabe()
def screwdriver(event): #Screwdriver
GPIO.output(2,False)
GPIO.output(6,False)
time.sleep(10*n)
GPIO.output(6,True)
time.sleep(20*n)
GPIO.output(2,True)
kanister[1] = kanister[1]-20
kanister[5] = kanister[5]-10
ausgabe()
def simplered(event): #Simple Red
GPIO.output(2,False)
GPIO.output(3,False)
GPIO.output(6,False)
GPIO.output(18,False)
time.sleep(3*n)
GPIO.output(3,True)
time.sleep(3*n)
GPIO.output(6,True)
time.sleep(4*n)
GPIO.output(2,True)
GPIO.output(18,True)
kanister[1] = kanister[1]-10
kanister[2] = kanister[2]-3
kanister[5] = kanister[5]-6
kanister[7] = kanister[7]-10
ausgabe()
def springtimecooler(event): #Springtime Cooler
GPIO.output(2,False)
GPIO.output(4,False)
GPIO.output(6,False)
GPIO.output(17,False)
time.sleep(4*n)
GPIO.output(17,True)
time.sleep(2*n)
GPIO.output(4,True)
time.sleep(2*n)
GPIO.output(6,True)
time.sleep(4*n)
GPIO.output(2,True)
kanister[1] = kanister[1]-12
kanister[3] = kanister[3]-6
kanister[5] = kanister[5]-8
kanister[6] = kanister[6]-4
ausgabe()
def tequilasunrise(event): #Tequila Sunrise
GPIO.output(2,False)
GPIO.output(3,False)
GPIO.output(4,False)
GPIO.output(5,False)
time.sleep(2*n)
GPIO.output(4,True)
time.sleep(1*n)
GPIO.output(3,True)
time.sleep(6*n)
GPIO.output(5,True)
time.sleep(7*n)
GPIO.output(2,True)
kanister[1] = kanister[1]-16
kanister[2] = kanister[2]-3
kanister[3] = kanister[3]-2
kanister[4] = kanister[4]-9
ausgabe()
top = Tkinter.Tk() # Erzeugen eines Fensters
top.geometry("1024x900")
w = Tkinter.Label(top,text='Choose your Cocktail') #Header
w.grid(row=0,column=3)
"""
def wechslefarbe ():
knopf["bg"]="#FF0000"
knopf["fg"]="#FF0000"
knopf1["bg"]="#FF0000"
knopf1["fg"]="#FF0000"
knopf2["bg"]="#FF0000"
knopf2["fg"]="#FF0000"
knopf3["bg"]="#FF0000"
knopf3["fg"]="#FF0000"
knopf4["bg"]="#FF0000"
knopf4["fg"]="#FF0000"
knopf5["bg"]="#FF0000"
knopf5["fg"]="#FF0000"
knopf6["bg"]="#FF0000"
knopf6["fg"]="#FF0000"
knopf7["bg"]="#FF0000"
knopf7["fg"]="#FF0000"
knopf8["bg"]="#FF0000"
knopf8["fg"]="#FF0000"
knopf9["bg"]="#FF0000"
knopf9["fg"]="#FF0000"
knopf10["bg"]="#FF0000"
knopf10["fg"]="#FF0000"
knopf11["bg"]="#FF0000"
knopf11["fg"]="#FF0000"
knopf12["bg"]="#FF0000"
knopf12["fg"]="#FF0000"
knopf13["bg"]="#FF0000"
knopf13["fg"]="#FF0000"
knopf14["bg"]="#FF0000"
knopf14["fg"]="#FF0000"
time.sleep(20*n)
liste= Listbox(root,height=5)
liste.insert("end","All in One")
liste.insert("end","Alice Deluxe")
liste.insert("end","Baltic")
liste.grid(row=1,column=1)
"""
knopf = Tkinter.Button(top,text='All in One',height=12,width=22,command=wechslefarbe)
knopf.grid(row=1,column=1)
knopf.bind('<Button-1>', allinone)
knopf1 = Tkinter.Button(top,text='Alice Deluxe',height=12,width=22,command=wechslefarbe)
knopf1.grid(row=1,column=2)
knopf1.bind('<Button-1>', alicedeluxe)
knopf2 = Tkinter.Button(top,text='Baltic',height=12,width=22)
knopf2.grid(row=1,column=3)
knopf2.bind('<Button-1>', baltic)
knopf3 = Tkinter.Button(top,text='Black Death',height=12,width=22)
knopf3.grid(row=1,column=4)
knopf3.bind('<Button-1>', blackdeath)
knopf4 = Tkinter.Button(top,text='El Dorado',height=12,width=22)
knopf4.grid(row=1,column=5)
knopf4.bind('<Button-1>', eldorado)
knopf5 = Tkinter.Button(top,text='Emerald Dream',height=12,width=22)
knopf5.grid(row=2,column=1)
knopf5.bind('<Button-1>', emeralddream)
knopf6 = Tkinter.Button(top,text='Exotic Blue',height=12,width=22)
knopf6.grid(row=2,column=2)
knopf6.bind('<Button-1>', exoticblue)
knopf7 = Tkinter.Button(top,text='Festini',height=12,width=22)
knopf7.grid(row=2,column=3)
knopf7.bind('<Button-1>', festini)
knopf8 = Tkinter.Button(top,text='Florida Sunrise',height=12,width=22)
knopf8.grid(row=2,column=4)
knopf8.bind('<Button-1>', floridasunrise)
knopf9 = Tkinter.Button(top,text='Green Eyes',height=12,width=22)
knopf9.grid(row=2,column=5)
knopf9.bind('<Button-1>', greeneyes)
knopf10 = Tkinter.Button(top,text='Green Poisen',height=12,width=22)
knopf10.grid(row=3,column=1)
knopf10.bind('<Button-1>', greenpoisen)
knopf11 = Tkinter.Button(top,text='Gruene Wiese',height=12,width=22)
knopf11.grid(row=3,column=2)
knopf11.bind('<Button-1>', gruenewiese)
knopf12 = Tkinter.Button(top,text='Happy Hour',height=12,width=22)
knopf12.grid(row=3,column=3)
knopf12.bind('<Button-1>', happyhour)
knopf13 = Tkinter.Button(top,text='Hawaiian Vodka',height=12,width=22)
knopf13.grid(row=3,column=4)
knopf13.bind('<Button-1>', hawaiianvodka)
knopf14 = Tkinter.Button(top,text='Knock Out',height=12,width=22)
knopf14.grid(row=3,column=5)
knopf14.bind('<Button-1>', knockout)
"""
knopf15 = Tkinter.Button(top,text='Mexicano')
knopf15.pack()
knopf15.bind('<Button-1>', mexicano)
knopf16 = Tkinter.Button(top,text='Pink Pussycat')
knopf16.pack()
knopf16.bind('<Button-1>', pinkpussycat)
knopf17 = Tkinter.Button(top,text='Screwdriver')
knopf17.pack()
knopf17.bind('<Button-1>', screwdriver)
knopf18 = Tkinter.Button(top,text='Simple Red')
knopf18.pack()
knopf18.bind('<Button-1>', simplered)
knopf19 = Tkinter.Button(top,text='Springtime Cooler')
knopf19.pack()
knopf19.bind('<Button-1>', springtimecooler)
knopf20 = Tkinter.Button(top,text='Tequila Sunrise')
knopf20.pack()
knopf20.bind('<Button-1>', tequilasunrise)
"""
top.mainloop()