我正在创建一个应用程序,它使用混合框架来帮助组织。我一共使用了 3 个,它们被包装在左侧、右侧和顶部。然后我最初使用网格来组织其中的小部件。但是,我打包到右侧的 sub_frame 被打包在另一个打包到顶部的 sub_frame 之上。我不知道为什么会这样。但是,我尝试在其中一个 sub_frames 中使用 pack 以使其更简单。然后我遇到了这个错误:Traceback (most recent call last): File "E:/Python/Py_Proj/Attempt at treeview.py", line 78, in <module> app = App(window) File "E:/Python/Py_Proj/Attempt at treeview.py", line 42, in __init__ self.Banner_Label.grid(row=0,column=0) File "C:\Users\Green\AppData\Local\Programs\Python\Python36\lib\tkinter\__init__.py", line 2223, in grid_configure + self._options(cnf, kw))_tkinter.TclError: cannot use geometry manager grid inside . which already has slaves managed by pack这是代码:import tkinter as tkfrom tkinter import ttkuser_list = [("foo", 3), ("bar", 3), ("Terri", 2), ("Chris", 2), ("Tony", 2), ("Emma", 2), ("Thomas", 1), ("Penny", 1), ("Kamryn", 1), ("Kelsie", 1), ("James", 1), ("Connor", 1), ("Steve", 1), ("Bob", 2), ("Elon", 1), ("Albert", 1), ("Brian", 1), ("Sam", 1), ("Karen", 1), ("Sophie", 1), ("Leo", 1), ("Alfie", 1), ("Alan", 1), ("Turing", 3), ("Reeves", 2), ("Greene", 2), ("Seal", 2), ("Keeble", 1), ("Bailey", 1), ("Kaey", 1), ("Joe", 1), ("Lauren", 1), ("Lasagna", 1), ("Morris", 1), ("Quinn", 1), ("Mitchell", 2)]class App(tk.Frame): def __init__(self,master): tk.Frame.__init__(self,master) self.master = master # Tree Frame self.Tree_Frame = tk.Frame(self, width=200, height=200).pack(side=tk.LEFT) self.Tree = ttk.Treeview(self.Tree_Frame, columns=("a", "b")) self.Tree['show'] = 'headings' self.Tree["columns"] = ("User", "Clearance") self.Tree.heading("User", text="Name") self.Tree.heading("Clearance", text="Clearance") self.Tree.column("User", width=100, anchor="center") self.Tree.column("Clearance", width=80, anchor="center")
1 回答
沧海一幻觉
TA贡献1824条经验 获得超5个赞
问题是这一行:
self.Banner_Frame = tk.Frame(self,width=200,height=200).pack(side=tk.TOP)
您需要一个横幅框架小部件的参考,它应该是:
self.Banner_Frame = tk.Frame(self,width=200,height=200)
self.Banner_Frame.pack(side=tk.TOP)
您现在正在做的是None作为小部件的主人传递。
我还注意到您正在将其master作为参数,但没有打包您的App框架。如果是这样,您还需要master在创建框架时通过:
self.Tree_Frame = tk.Frame(master, width=200, height=200)
....
self.Func_Frame = tk.Frame(master, width=200, height=200)
....
self.Banner_Frame = tk.Frame(master,width=200,height=200)
或者,简单地做一个self.pack().
添加回答
举报
0/150
提交
取消