我正在尝试开发一个简单的 Gui,当单击菜单中的按钮时显示不同的页面,并且我已经能够使其他按钮工作,但菜单给我错误。就像菜单中的其他应用程序一样,人们可以在该应用程序中导航。当我运行代码并单击文件菜单中的 newtest 时,出现此错误
Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python3.7/tkinter/__init__.py", line 1705, in __call__
return self.func(*args)
File "/home/pi/Documents/py script/helium1/test.py", line 34, in <lambda>
command=lambda: controller.show_frame(PageOne))
AttributeError: 'Frame' object has no attribute 'show_frame'
这是代码
import tkinter as tk
from tkinter import *
import datetime
import time
import paho.mqtt.client as mqtt
LARGE_FONT= ("Verdana", 12)
def messageFunction (client, userdata, message):
topic = str(message.topic)
message = str(message.payload.decode("utf-8"))
print(topic + " " + message)
HeliumClient = mqtt.Client("xokaxvwt")
HeliumClient.username_pw_set(username = "xokaxvwt", password="MGlEiIwOHM9-")
HeliumClient.connect("m16.cloudmqtt.com", 15998)
HeliumClient.subscribe("Switch_1")
HeliumClient.subscribe("Switch_2")
HeliumClient.on_message = messageFunction
HeliumClient.loop_start()
class MenuBar(tk.Menu):
def __init__(self, parent, controller):
tk.Menu.__init__(self, controller)
self.controller = controller
fileMenu = tk.Menu(self, tearoff=0)
self.add_cascade(label="File", underline=0, menu=fileMenu)
fileMenu.add_command(label="New Test",
command=lambda: controller.show_frame(PageOne))
fileMenu.add_separator()
fileMenu.add_command(label="Exit")
慕雪6442864
相关分类