【发布时间】:2022-06-11 20:34:48
【问题描述】:
我正在尝试编写一个带有两个框架和一个控制器的简单 tkinter 应用程序。但是,当我尝试在控制器中实现 Notebook 小部件时,它似乎什么也没做。
import tkinter as tk
from tkinter import ttk
class WrapFrame(tk.Frame):
def __init__(self, root):
super().__init__(root)
class UnwrapFrame(tk.Frame):
def __init__(self, root):
super().__init__(root)
class Controller(tk.Frame):
def __init__(self, root):
super().__init__(root)
# Notebook
notebook = ttk.Notebook(self)
wrap_frame = WrapFrame(notebook)
unwrap_frame = UnwrapFrame(notebook)
notebook.add(wrap_frame, text="Wrap")
notebook.add(unwrap_frame, text="Unwrap")
notebook.pack()
class App(tk.Tk):
def __init__(self):
super().__init__()
self.title('Mod')
self.geometry('300x200')
self.resizable(False, False)
app = App()
Controller(app)
app.mainloop()
输出:
【问题讨论】: