我正在创建一个应用程序,它使用混合框架来帮助组织。我一共使用了 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 tk
from tkinter import ttk
user_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")
沧海一幻觉
相关分类