_tkinter.TclError:未知选项“-menu”

时间:2017-12-20 07:41:20

标签: python-3.x tkinter

我正在尝试用Python编写面向对象的代码。现在我遇到了一个错误:

  

_tkinter.TclError:未知选项“-menu”

我认为错误在于以下几行:

self.config(menu=menubar)

以下是我的代码:

import tkinter as tk
from tkinter import ttk
from PIL import Image, ImageTk
import time
LARGE_FONT = ("Verdana", 12)
class ImgComp(tk.Tk):

    def __init__(self, *args, **kwargs):

        tk.Tk.__init__(self, *args, **kwargs)        
        container = tk.Frame(self,width=320, height=209)        
        container.pack(side="top")
        container.grid_rowconfigure(0, weight=1)
        container.grid_columnconfigure(0, weight=1)
        container.grid_propagate(False)

        self.frames = {}

        for F in (PageOne):

            frame = F(container, self)
            #frame['bg'] = 'red'
            self.frames[F] = frame

            frame.grid(row=0, column=0, sticky="nsew")

        self.show_frame(PageOne)        

    def show_frame(self, cont):

        frame = self.frames[cont]
        frame.tkraise()

class PageOne(tk.Frame):

    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        menubar = tk.Menu(self)
        filemenu = tk.Menu(menubar, tearoff=0)
        filemenu.add_command(label="New")
        filemenu.add_command(label="Open")                    
        menubar.add_cascade(label="Settings", menu=filemenu)        
        self.config(menu=menubar)
        label = tk.Label(self, text="Page One", font=LARGE_FONT)
        label.pack(pady=10,padx=10)            

app = ImgComp()
app.mainloop()

另外我想通知,我已经截断了代码,因为我不允许通过stackoverflow发布更大的代码。请帮忙。

0 个答案:

没有答案