与这个战斗太久了,想知道有人会指出我正确的方向。我正在尝试建立一个应用程序,当该应用程序由连接到rasberry pi的红外传感器触发时,会打开一个带有7个按钮的框架。我希望按下按钮时可以打开要附加图像的单独框架。我希望框架在给定时间后消失。
现在,我可以在起始页上执行此操作,创建框架和画布并加载图像,然后在7秒钟后使用after和destroy摆脱它就可以了。
但是,当我尝试将其他框架引入方程式时,我似乎无法在第二框架中使用画布或图像。我更改了当前的方法,将其设置为分类(在线学习教程),但最终也陷入僵局。
我不确定,但是我有种感觉,现在我已经与框架建立了主从关系,这意味着我无法分别自定义它们?我已经附加了当前正在播放的与框架相关的代码。如果有人可以提供建议,将不胜感激。
import tkinter as tk
from tkinter import *
LARGE_FONT= ("Verdana", 12)
class SeaofBTCapp(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
container = tk.Frame(self)
container.pack(side="top", fill="both", expand = True)
container.grid_rowconfigure(100, weight=1)
container.grid_columnconfigure(100, weight=1)
self.frames = {}
for F in (StartPage, PageOne, PageTwo, PageThree, PageFour, PageFive, PageSix, PageSeven):
frame = F(container, self)
self.frames[F] = frame
frame.grid(row=0, column=0, sticky="nsew")
self.show_frame(StartPage)
def show_frame(self, cont):
frame = self.frames[cont]
frame.tkraise()
class StartPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self,parent)
label = tk.Label(self, text="SMART BIN Tech", font=LARGE_FONT)
label.pack(pady=10,padx=10)
button = tk.Button(self, text="NO DRINKS or FOOD WASTE",
command=lambda: controller.show_frame(PageOne))
button.pack()
button2 = tk.Button(self, text="NO PAPER WASTE",
command=lambda: controller.show_frame(PageTwo))
button2.pack()
button3 = tk.Button(self, text="NO TEA BAGS",
command=lambda: controller.show_frame(PageThree))
button3.pack()
button4 = tk.Button(self, text="NO CANS or PLASTICS",
command=lambda: controller.show_frame(PageFour))
button4.pack()
button5 = tk.Button(self, text="LIST of RECYCLABLES",
command=lambda: controller.show_frame(PageFive))
button5.pack()
button6 = tk.Button(self, text="Vending Area Performance",
command=lambda: controller.show_frame(PageSix))
button6.pack()
button7 = tk.Button(self, text="UBS UK RATIO",
command=lambda: controller.show_frame(PageSeven))
button7.pack()
class PageOne(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
label = tk.Label(self, text="NO DRINKS or FOOD WASTE", font=LARGE_FONT)
label.pack(pady=10,padx=10)
button1 = tk.Button(self, text="Back to Home",
command=lambda: controller.show_frame(StartPage))
button1.pack()
class PageTwo(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
label = tk.Label(self, text="NO PAPER WASTE", font=LARGE_FONT)
label.pack(pady=10,padx=10)
button1 = tk.Button(self, text="Back to Home",
command=lambda: controller.show_frame(StartPage))
button1.pack()
class PageThree(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
label = tk.Label(self, text="NO TEA BAGS", font=LARGE_FONT)
label.pack(pady=10,padx=10)
button1 = tk.Button(self, text="Back to Home",
command=lambda: controller.show_frame(StartPage))
button1.pack()
class PageFour(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
label = tk.Label(self, text="NO CANS or PLASTICS", font=LARGE_FONT)
label.pack(pady=10,padx=10)
button1 = tk.Button(self, text="Back to Home",
command=lambda: controller.show_frame(StartPage))
button1.pack()
class PageFive(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
label = tk.Label(self, text="RECYCLABLES", font=LARGE_FONT)
label.pack(pady=10,padx=10)
button1 = tk.Button(self, text="Back to Home",
command=lambda: controller.show_frame(StartPage))
button1.pack()
class PageSix(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
label = tk.Label(self, text="Vending Area Performance", font=LARGE_FONT)
label.pack(pady=10,padx=10)
w = tk.Canvas(self,width=400,height=500)
w.pack
button1 = tk.Button(self, text="Back to Home",
command=lambda: controller.show_frame(StartPage))
button1.pack()
class PageSeven(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
label = tk.Label(self, text="UBS UK RATIO", font=LARGE_FONT)
label.pack(pady=10,padx=10)
canvas = tk.Canvas(self,width=100, height=100)
canvas.pack
button1 = tk.Button(self, text="Back to Home",
command=lambda: controller.show_frame(StartPage))
button1.grid(row=2, column=5)
button1.pack()
app = SeaofBTCapp()
app.mainloop()