简体   繁体   中英

TclError: Unkown option '-menu' using tkinter on python3.7

Learning how to use tkinter and I'm getting an error I don't understanding it, as it doesn't really make sense to me. It states that the option "-menu" isn't recognized, but... I don't use it?

Thanks for reading and possibly helping!

import tkinter as tk


LARGE_FONT = ('Verdana', 12)


class CofBTC(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 = {}

        frame = startPage(container,self)

        self.frames[startPage] = frame

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

        self.showFrame(startPage)

    def showFrame(self, cont):

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

class startPage(tk.Frame):

    def __init__(self, parent, controller):

        tk.Frame.__init__(self, parent, controller)
        label = tk.Label(self, text = 'Start Page', font = LARGE_FONT)
        label.pack(pady=10, padx=10)

root= tk.Tk('TestTkinter')

app = CofBTC()
app.mainloop()

Edit: Was asked for the full error message, so here it is (I don't really understand it, so for some reason I didn't think about the fact that some people actually do understand these lol):

Traceback (most recent call last):

  File "<ipython-input-4-9a8fe12ef0a8>", line 1, in <module>
    runfile('C:/Users/danburnier/Desktop/Music21/sanstitre4.py', wdir='C:/Users/danburnier/Desktop/Music21')

  File "C:\Users\danburnier\AppData\Local\Continuum\anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 827, in runfile
    execfile(filename, namespace)

  File "C:\Users\danburnier\AppData\Local\Continuum\anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "C:/Users/danburnier/Desktop/Music21/sanstitre4.py", line 52, in <module>
    app = CofBTC()

  File "C:/Users/danburnier/Desktop/Music21/sanstitre4.py", line 29, in __init__
    frame = startPage(container,self)

  File "C:/Users/danburnier/Desktop/Music21/sanstitre4.py", line 46, in __init__
    tk.Frame.__init__(self, parent, controller)

  File "C:\Users\danburnier\AppData\Local\Continuum\anaconda3\lib\tkinter\__init__.py", line 2744, in __init__
    Widget.__init__(self, master, 'frame', cnf, {}, extra)

  File "C:\Users\danburnier\AppData\Local\Continuum\anaconda3\lib\tkinter\__init__.py", line 2299, in __init__
    (widgetName, self._w) + extra + self._options(cnf))

TclError: unknown option "-menu"`

Problem is because you send controller to Frame

tk.Frame.__init__(self, parent, controller)

and it doesn't know what to do with this unexpected element

You need

tk.Frame.__init__(self, parent)

BTW: If you inherit from tk.Tk - class CofBTC(tk.Tk) then you don't need root= tk.Tk('TestTkinter') because tkinter should use only one window create with Tk()


In Python 3 you can use super()

    #tk.Tk.__init__(self, *args, **kwargs)
    super().__init__(*args, **kwargs)

and

    #tk.Frame.__init__(self, parent)
    super().__init__(parent)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM