Ошибка, сообщенная в моей коробке Windows с Python 3.7.1, отличается от вашей.Мой _tkinter.TclError: unknown option "-menu"
.Это потому, что опция menu
поддерживается только контейнерами верхнего уровня, а не для виджета Frame
.
Ниже приведен модифицированный код, основанный на вашем, который исправляет ошибку:
import tkinter as tk
class pyFinanceStart(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
self.geometry("300x100")
# make the frame using all the window area
self.rowconfigure(0, weight=1)
self.columnconfigure(0, weight=1)
# create the pages
self.frames = {}
for F in (StartPage,):
frame = F(self)
frame.grid(row=0, column=0, sticky="nsew")
self.frames[F] = frame
# show the start page
self.show_frame(StartPage)
def show_frame(self, cont):
frame = self.frames[cont]
frame.tkraise()
class StartPage(tk.Frame):
def __init__(self, parent):
tk.Frame.__init__(self, parent, bg='blue')
tk.Label(self, text="Start Page", bg='#ffc').pack(fill='both', expand=1, padx=10, pady=10)
# create the menubar
menubar = tk.Menu(parent)
# create the 'Top Indicator' menu
topIndi = tk.Menu(menubar, tearoff=1)
topIndi.add_command(label="None")
topIndi.add_separator()
topIndi.add_command(label="RSI")
topIndi.add_command(label="MACD")
menubar.add_cascade(label="Top Indicator", menu=topIndi)
# create the 'Help' menu
helpmenu = tk.Menu(menubar, tearoff=0)
helpmenu.add_command(label="Help")
menubar.add_cascade(label="Help", menu=helpmenu)
# set the toplevel menubar
parent.config(menu=menubar) # or tk.Tk.config(parent, menu=menubar)
pyFinanceStart().mainloop()
Ивыход:
