多个命令有问题,命令不起作用

因此,我正在使用Raspberry Pi 4进行一个项目来构建饮料分配器。我有4个泵,它们都与4通道Relais连接。我在GPIO17上连接了他的First Pump。所以要夸奖我在做什么。您可以选择饮料,然后选择杯子的大小。当您单击其中一种尺寸时,将出现一个负载屏幕,装有饮料的泵应将其泵入您的杯子中。一定时间后,它会返回首页。这是代码:

import RPi.GPIO as GPIO
from tkinter import *
from tkinter import ttk
import time
import urllib
import json
import sys

class GUI(tk.Tk):
    def __init__(self, *args, **kwargs):
        tk.Tk.__init__(self, *args, **kwargs)
        tk.Tk.wm_title(self, "Raspberrypi GUI")
        tk.Tk.wm_attributes(self, "-fullscreen", True)

        container = tk.Frame(self)
        container.pack(side="top", fill="both", expand=True)
        container.grid_rowconfigure(0, weight=1)
        container.grid_columnconfigure(0, weight=1)

        self.frames = {}
        for F in (FirstPage, PageTwo, ColaPage, WasserPage, FuseTeaPage, ladebildschirm,ladebildschirm2):
            frame = F(container, self)
            self.frames[F] = frame
            frame.grid(row=0, column=0, sticky="nsew")

        self.show_frame(FirstPage)

    def Pumpe1(self):
        GPIO.setmode(GPIO.BCM)
        GPIO.setup(17, GPIO.LOW)
        time.sleep(5)
        GPIO.setup(17, GPIO.HIGH)
        GPIO.cleanup()

    def show_frame(self, cont):

        frame = self.frames[cont]
        frame.tkraise()
        if cont == ladebildschirm:
            self.after(5000, self.show_frame, FirstPage)
        if cont == ladebildschirm2:
            self.after(7000, self.show_frame, FirstPage)


class FirstPage (tk.Frame):
    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        photo = tk.PhotoImage(file="drinks.png")
        BackgroundLabel = tk.Label(self,image=photo)
        BackgroundLabel.image = photo
        BackgroundLabel.place(x=0,y=0,width=800,height=480)

        button = tk.Button(self, bg="gray88",text="Drinks",command=lambda: controller.show_frame(PageTwo), height = 3, width= 16)
        button.place(x=120,y=200)


        button1 = tk.Button(self,bg="gray88",text="About",command=lambda: controller.show_frame(),height= 3, width = 16 )
        button1.place(x=600,y=200)



class PageTwo (tk.Frame):

    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent, bg="light cyan")


        logo1 = tk.PhotoImage(file="news.782-120x120.png")
        Label1 = tk.Label(self,image=logo1,)
        Label1.image = logo1
        Label1.place(x=180,y=60,width=120, height=120)

        logo2 = tk.PhotoImage(file="fusetea.png")
        Label2 = tk.Label(self,image=logo2)
        Label2.image = logo2
        Label2.place(x=180,y=260,width=120, height=120)

        logo3 = tk.PhotoImage(file="Unbenannt.png")
        Label3 = tk.Label(self,image=logo3)
        Label3.image = logo3
        Label3.place(x=450,y=60,width=120, height=120)

        logo4 = tk.PhotoImage(file="")
        Label4 = tk.Label(self,image=logo4)
        Label4.image = logo4
        Label4.place(x=450,y=260,width=120, height=120)




        button1 = tk.Button(self,bg="IndianRed1", text="Back",command=lambda: controller.show_frame(FirstPage), height = 2, width=15)
        button1.grid(padx=2,pady=2,sticky=NW)


        Button2 = tk.Button(self,bg="gray80", text="Coca Cola", command=lambda: controller.show_frame(ColaPage), height=2, width= 15)
        Button2.place(x=180,y=200)


        Button3 = tk.Button(self,bg="gray80", text="Fusetea", command=lambda: controller.show_frame(FuseTeaPage), height=2, width= 15)
        Button3.place(x=180,y=400)

        Button4 = tk.Button(self,bg="gray80", text="Wasser", command=lambda: controller.show_frame(WasserPage), height=2, width= 15)
        Button4.place(x=450,y=200)

        Button5 = tk.Button(self,bg="gray80", text="?", command=lambda: controller.show_frame(), height=2, width= 15)
        Button5.place(x=450,y=400)

class ColaPage (tk.Frame):

    def __init__(self,parent, controller):
        tk.Frame.__init__(self, parent, bg="light cyan")

        logo1 = tk.PhotoImage(file="becherklein.png")
        Label1 = tk.Label(self,image=logo1)
        Label1.image = logo1
        Label1.place(x=180,y=150,width=120, height=120)

        logo2 = tk.PhotoImage(file="bechermittel.png")
        Label2 = tk.Label(self,image=logo2)
        Label2.image = logo2
        Label2.place(x=450,y=150,width=120, height=120)

        button1 = tk.Button(self,bg="gray85", text="150ml", command=lambda:[controller.show_frame(ladebildschirm),pumpe1()], height=2 , width=16)
        button1.place(x=180,y=300)

        button = tk.Button(self,bg="IndianRed1", text="Back",command=lambda: controller.show_frame(PageTwo), height = 2, width=15)
        button.grid(padx=2,pady=2,sticky=NW)

        button2 = tk.Button(self,bg="gray85", text="300ml", command=lambda:controller.show_frame(ladebildschirm2), height=2, width=16)
        button2.place(x=450,y=300)

class WasserPage(tk.Frame):

    def __init__(self,parent, controller):
        tk.Frame.__init__(self, parent, bg="light cyan")

        logo1 = tk.PhotoImage(file="becherklein.png")
        Label1 = tk.Label(self,image=logo1)
        Label1.image = logo1
        Label1.place(x=180,y=150,width=120, height=120)

        logo2 = tk.PhotoImage(file="bechermittel.png")
        Label2 = tk.Label(self,image=logo2)
        Label2.image = logo2
        Label2.place(x=450,y=150,width=120, height=120)

        button1 = tk.Button(self,bg="gray85", text="150ml", command=lambda:controller.show_frame(ladebildschirm), height=2 , width=16)
        button1.place(x=180,y=300)

        button = tk.Button(self,bg="IndianRed1", text="Back",command=lambda: controller.show_frame(PageTwo), height = 2, width=15)
        button.grid(padx=2,pady=2,sticky=NW)

        button2 = tk.Button(self,bg="gray85", text="300ml", command=lambda:controller.show_frame(ladebildschirm2), height=2, width=16)
        button2.place(x=450,y=300)

class FuseTeaPage(tk.Frame):
    def __init__(self,parent, controller):
        tk.Frame.__init__(self, parent, bg="light cyan")

        logo1 = tk.PhotoImage(file="becherklein.png")
        Label1 = tk.Label(self,image=logo1)
        Label1.image = logo1
        Label1.place(x=180,y=150,width=120, height=120)

        logo2 = tk.PhotoImage(file="bechermittel.png")
        Label2 = tk.Label(self,image=logo2)
        Label2.image = logo2
        Label2.place(x=450,y=150,width=120, height=120)

        button1 = tk.Button(self,bg="gray85", text="150ml", command=lambda: controller.show_frame(ladebildschirm), height=2 , width=16,)        
        button1.place(x=180,y=300)

        button = tk.Button(self,bg="IndianRed1", text="Back",command=lambda: controller.show_frame(PageTwo), height = 2, width=15)
        button.grid(padx=2,pady=2,sticky=NW)

        button2 = tk.Button(self,bg="gray85", text="300ml",height=2, width=16,command=lambda: controller.show_frame(ladebildschirm2))
        button2.place(x=450,y=300)



class ladebildschirm(tk.Frame):
        def __init__(self,parent, controller):
            tk.Frame.__init__(self, parent, bg="light cyan",)

            text = tk.Label(self,font=("Helvetica", 20),text="Bitte Warten \n Ihr Getränk wird eingeschenkt")
            text.place(x=215,y=200,)


class ladebildschirm2(tk.Frame):
        def __init__(self,parent, controller):
            tk.Frame.__init__(self, parent, bg="light cyan",)

            text = tk.Label(self,font=("Helvetica", 20),text="Bitte Warten \n Ihr Getränk wird eingeschenkt")
            text.place(x=215,y=200,)



app = GUI()
app.geometry("800x480")
app.mainloop() 

我想在ColaPage,WasserPage和FuseTeaPage上放置一个使用Ladebildschirm激活每个Pump的命令。 150毫升和300毫升的尺寸相当于杯子的大小,因此需要定义它们需要激活多长时间。 150ml是5秒,而300ml是7秒。我首先制作了150ml,并将其定义为Pump1,然后在其中输入Time命令,如下所示:

        GPIO.setmode(GPIO.BCM)
        GPIO.setup(17, GPIO.LOW)
        time.sleep(5)
        GPIO.setup(17, GPIO.HIGH)
        GPIO.cleanup()

然后,将其与Button1放在Colapage上的Multiple Function上,如下所示:


    def __init__(self,parent, controller):
        tk.Frame.__init__(self, parent, bg="light cyan")

        logo1 = tk.PhotoImage(file="becherklein.png")
        Label1 = tk.Label(self,image=logo1)
        Label1.image = logo1
        Label1.place(x=180,y=150,width=120, height=120)

        logo2 = tk.PhotoImage(file="bechermittel.png")
        Label2 = tk.Label(self,image=logo2)
        Label2.image = logo2
        Label2.place(x=450,y=150,width=120, height=120)

        button1 = tk.Button(self,bg="gray85", text="150ml", command=lambda:[controller.show_frame(ladebildschirm),pumpe1()], height=2 , width=16)
        button1.place(x=180,y=300)

        button = tk.Button(self,bg="IndianRed1", text="Back",command=lambda: controller.show_frame(PageTwo), height = 2, width=15)
        button.grid(padx=2,pady=2,sticky=NW)

        button2 = tk.Button(self,bg="gray85", text="300ml", command=lambda:controller.show_frame(ladebildschirm2), height=2, width=16)
        button2.place(x=450,y=300)

但是泵不会继续运转。因此,仅出现负载屏幕,并在5秒钟后返回到主页,但泵未继续运行。当我仅以其他代码命令泵时,泵功能。但是在这里它不会。