【发布时间】:2024-04-20 18:05:01
【问题描述】:
我正在尝试制作一个简单的菜单(目前),但我不断收到此错误:
class pyFinanceStart(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(0, weight=1)
container.grid_columnconfigure(0, weight=1)
self.frames = {}
for F in (StartPage):
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)
container = tk.Frame(self)
container.pack(side="top", fill="both", expand = True)
container.grid_rowconfigure(0, weight=1)
container.grid_columnconfigure(0, weight=1)
menubar = tk.Menu(container)
topIndi = tk.Menu(menubar, tearoff=1)
topIndi.add_command(label="None")#,command=lambda: addTopIndicator('none'))
topIndi.add_separator()
topIndi.add_command ( label="RSI")#,command=lambda: addTopIndicator('rsi'))
topIndi.add_command ( label="MACD")#,command=lambda: addTopIndicator('macd'))
menubar.add_cascade(label = "Top Indicator", menu = topIndi)
helpmenu = tk.Menu(menubar, tearoff=0)
helpmenu.add_command(label="Help")
menubar.add_cascade(label="Help", menu=helpmenu)
tk.Tk.config(self, menu=menubar)
我有错误:AttributeError: module 'tkinter' has no attribute 'config'
【问题讨论】:
-
不是我在使用 python 3.x
-
请发布堆栈跟踪以及任何其他有助于调试问题的信息。
-
您需要在问题中包含足够多的代码,以便其他人重现该问题。请edit 这样做。当我尝试按照当前发布的方式运行您的代码时,我在
tk.Tk.config(self, menu=menubar)行上收到另一个错误——这确实是错误的。
标签: python python-3.x tkinter attributeerror