Python 无法在内部使用几何图形管理器栅格。它已经有了由pack管理的奴隶

Python 无法在内部使用几何图形管理器栅格。它已经有了由pack管理的奴隶,python,tkinter,Python,Tkinter,因此,我正在编写一个小应用程序,我得到了以下错误: 无法在内部使用几何图形管理器栅格。它已经有了由pack管理的奴隶 在StartPage中会变得很麻烦。uuu init_uuuuuu()我开始使用网格添加标签,但在StartPage中甚至在StartPage上都看不到我在使用pack的任何地方。我遗漏了什么吗?页面中的小部件的父项不正确。您没有指定父级,因此它默认为根窗口,您正在根窗口中使用pack。谢谢,真不敢相信我错过了这么久。现在效果很好。可能是 import tkinter as tk

因此,我正在编写一个小应用程序,我得到了以下错误:

无法在内部使用几何图形管理器栅格。它已经有了由pack管理的奴隶


在StartPage中会变得很麻烦。uuu init_uuuuuu()我开始使用网格添加标签,但在StartPage中甚至在StartPage上都看不到我在使用pack的任何地方。我遗漏了什么吗?

页面中的小部件的父项不正确。您没有指定父级,因此它默认为根窗口,您正在根窗口中使用
pack

谢谢,真不敢相信我错过了这么久。现在效果很好。可能是
import tkinter as tk
from tkinter import ttk



LARGE_FONT = ("Times New Roman", 16)
NORMAL_FONT = ("Times New Roman", 12)



def popup(title, string):
    popup = tk.Tk()
    popup.geometry('300x100')
    popup.wm_title(title)

    label = ttk.Label(popup, text=string)
    label.pack(pady=10)

    b1 = ttk.Button(popup, text='Okay', command=lambda:popup.destroy())
    b1.pack(pady=10)

class FECapp(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)

        tk.Tk.iconbitmap(self, default='icon.ico')
        tk.Tk.wm_title(self, 'Family Entertainment Center Management System')

        menu = tk.Menu(container)

        file = tk.Menu(menu)
        file.add_command(label='Login', command=lambda:popup('Not supported', 'This function is not supported yet.'))
        file.add_separator()
        file.add_command(label='Save Changes', command=lambda:popup('Not supported', 'This function is not supported yet.'))
        file.add_separator()
        file.add_command(label='Exit', command=lambda:exit())
        menu.add_cascade(label='File', menu=file)

        navigate = tk.Menu(menu)
        navigate.add_command(label='Home', command=lambda:self.show_frame(StartPage))
        navigate.add_command(label='Employee List', command=lambda:self.show_frame(Page1))
        menu.add_cascade(label='Navigate', menu=navigate)

        tk.Tk.config(self, menu=menu)

        self.frames = {}
        for F in (StartPage, Page1):
            frame = F(container, self)
            self.frames[F]=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)

        self.grid_rowconfigure(0, weight=1)
        self.grid_columnconfigure(0, weight=1)

        label1 = ttk.Label(text="Oops!", font=LARGE_FONT)
        #label1.pack(side='top', fill='y', expand=True)
        label1.grid(row=0, column=0, sticky='ns')

        label1 = ttk.Label(text="There doesn't seem to be anything here right now.", font=NORMAL_FONT)
        #label1.pack(side='top',fill='y', expand=True)
        label1.grid(row=1, column=0, sticky='ns')

class Page1(tk.Frame):

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

        listbox = MultiListbox(self,[('Row 1', 1, 'Item1'),('Row 2', 2, 'Item2'),('Row 3', 3, 'Item3'),('Row 4', 4, 'Item4')],['Row', 'Row (int)', 'Christmas List'])
        listbox.pack()


#Since tkinter has no multicolumn listbox, I suppose I'll make my own...
class MultiListbox(ttk.Frame):
    def __init__(self, master, data, headings):
        ttk.Frame.__init__(self, master)
        self.data=data

        self.tree = ttk.Treeview(self, columns=headings, show='headings')
        for head in headings:
            self.tree.heading(head, text=head)
        self.tree.pack()



app = FECapp()
app.geometry('1280x720')
app.mainloop()