gpt4 book ai didi

python - Tkinter 错误 : _tkinter. TclError:未知选项 "-menu"

转载 作者:太空宇宙 更新时间:2023-11-03 19:59:14 29 4
gpt4 key购买 nike

按照 YouTube 视频进行操作,但是我不断收到此 tkinter 错误,而且我没有任何线索来了解它的来源

代码:

import tkinter as tk

G_FONT=("Verdana", 12)


class CapApp(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.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, controller)
label = tk.Label(self, text="Start Page", font=G_FONT)
label.pack(pady=10, padx=10)


if __name__ == "__main__":
app = CapApp()
app.mainloop()

最佳答案

同意错误消息令人困惑。无论如何,您的代码中有一些错误 - 已修复并在下面代码的注释中注明:

import tkinter as tk

G_FONT=("Verdana", 12)


class CapApp(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.show_frame(StartPage)

# Fixed indentation so function is a class method.
def show_frame(self, cont):
frame = self.frames[cont]
frame.tkraise()


class StartPage(tk.Frame):

def __init__(self, parent, controller):
# You're passing too many arguments the base class __init__()
# tk.Frame.__init__(self, parent, controller)1
tk.Frame.__init__(self, parent)
label = tk.Label(self, text="Start Page", font=G_FONT)
label.pack(pady=10, padx=10)


if __name__ == "__main__":
app = CapApp()
app.mainloop()

关于python - Tkinter 错误 : _tkinter. TclError:未知选项 "-menu",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59351931/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com