所以我写了一个小应用程序,我收到了这个错误:
无法使用几何管理器网格。已经有包管理的奴隶
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()
在StartPage .__ init __()中我很挑剔,我开始使用网格添加标签,但我无法看到我在StartPage甚至在StartPage上使用pack的任何地方。我错过了什么吗?
答案 0 :(得分:2)
您网页中的小部件包含错误的父级。您没有指定父级,因此它默认为根窗口,并且您在根窗口中使用Authorization
。