【问题标题】:Tkinter Notebook widget not working as expectedTkinter Notebook 小部件未按预期工作
【发布时间】: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()

输出:

【问题讨论】:

    标签: python tkinter widget


    【解决方案1】:

    Controller 是一个框架。您永远不会在 Controller 的实例上调用 packplacegrid。由于它不可见,因此其中的所有内容也将不可见。

    你需要做这样的事情:

    controller = Controller(app)
    controller.pack(fill="both", expand=True)
    

    【讨论】:

      猜你喜欢
      • 2021-07-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-14
      • 1970-01-01
      • 2021-01-21
      • 1970-01-01
      • 2023-01-23
      相关资源
      最近更新 更多