报错 cannot use geometry manager grid inside . which already has slaves managed by pack
```python
from tkinter import *
from tkinter import ttk
class studentClass():
def __init__(self, master):
self.name = StringVar()
self.master = master
self.createStudent()
def createStudent(self):
# 设置主窗口背景颜色
self.master.configure(bg="#96CDCD")
# 创建一个大的容器,用于放置所有控件
container = Frame(self.master, bg="#96CDCD")
container.pack(pady=10, padx=10, fill=BOTH, expand=True)
# 创建标签和输入框区域
label_frame = Frame(container, bg="#96CDCD")
label_frame.pack(side=TOP, pady=(10, 5))
name_label = Label(label_frame, text="姓名:", bg="#96CDCD", fg="white")
name_label.pack(side=LEFT, padx=5)
self.name_entry = Entry(label_frame, textvariable=self.name, width=20)
self.name_entry.pack(side=LEFT, padx=5)
# 创建按钮区域
button_frame = Frame(container, bg="#96CDCD")
button_frame.pack(side=BOTTOM, pady=(5, 10))
query_button = Button(button_frame, text="查询", bg="#96CDCD", fg="white", command=self.query)
query_button.pack(side=LEFT, padx=10)
add_button = Button(button_frame, text="新增", bg="#96CDCD", fg="white", command=self.add)
add_button.pack(side=LEFT, padx=10)
import_button = Button(button_frame, text="导入", bg="#96CDCD", fg="white", command=self.import_data)
import_button.pack(side=LEFT, padx=10)
export_button = Button(button_frame, text="导出", bg="#96CDCD", fg="white", command=self.export_data)
export_button.pack(side=LEFT, padx=10)
# 创建表格区域
table_frame = Frame(container, bg="#96CDCD")
table_frame.pack(side=TOP, fill=X, expand=True)
columns = ("name", "sdept1", "sdept", "class","teacher","score","talent")
self.tree_view = ttk.Treeview(table_frame, show='headings', columns=columns, style="Treeview")
self.tree_view.tag_configure("oddrow", background="#EAEAEA")
self.tree_view.tag_configure("evenrow", background="#FFFFFF")
self.tree_view.column("name", width=80, anchor='center')
self.tree_view.column("sdept1", width=80, anchor='center')
self.tree_view.column("sdept", width=80, anchor='center')
self.tree_view.column("class", width=80, anchor='center')
self.tree_view.column("teacher", width=80, anchor='center')
self.tree_view.column("score", width=80, anchor='center')
self.tree_view.column("talent", width=80, anchor='center')
self.tree_view.heading('name', text="姓名")
self.tree_view.heading('sdept1', text="院系")
self.tree_view.heading('sdept', text="专业")
self.tree_view.heading('class', text="班级")
self.tree_view.heading('teacher', text="负责教师")
self.tree_view.heading('score', text="学生成绩")
self.tree_view.heading('talent', text="擅长领域")
infor=["韩浩","软件学院","新型平台软件","2205","胡春辉","100","体育"]
self.tree_view.insert("","end",text="Item1",values=infor)
self.tree_view.pack(pady=10, fill=BOTH, expand=True)
self.tree_view.bind("<Double-1>",self.tree_vi)
# 树形视图滚动条设置
vsb = Scrollbar(table_frame, orient="vertical", command=self.tree_view.yview)
vsb.pack(side=RIGHT, fill=Y)
hsb = Scrollbar(table_frame, orient="horizontal", command=self.tree_view.xview)
hsb.pack(side=BOTTOM, fill=X)
self.tree_view.configure(yscrollcommand=vsb.set, xscrollcommand=hsb.set)
def tree_vi(self,event=None):
ro=Tk()
ro.geometry("100x100")
ro.mainloop()
def query(self):
pass
def add(self):
roo=Tk()
roo.geometry("300x300")
Label(roo,text="姓名").grid(row=0,column=0,pady=5,padx=10)
Label(roo,text="院系").grid(row=1,column=0,pady=5)
Label(roo,text="专业").grid(row=2,column=0,pady=5)
Label(roo,text="班级").grid(row=3,column=0,pady=5)
Label(roo,text="负责教师").grid(row=4,column=0,pady=5)
Label(roo,text="学生成绩").grid(row=5,column=0,pady=5)
Label(roo,text="擅长领域").grid(row=6,column=0,pady=5)
Entry(roo).grid(row=0,column=1)
Entry(roo).grid(row=1,column=1)
Entry(roo).grid(row=2,column=1)
Entry(roo).grid(row=3,column=1)
Entry(roo).grid(row=4,column=1)
Entry(roo).grid(row=5,column=1)
Entry(roo).grid(row=6,column=1)
Button(root,text="新增").grid(row=7)
roo.mainloop()
def import_data(self):
pass
def export_data(self):
pass
class adminClass():
def __init__(self, master):
self.tree = None
self.master = master
# Button(master, text="这是招聘管理界面", font=("微软雅黑", 14), fg="white", bg="#96CDCD").pack()
self.createAdmin()
def createAdmin(self):
cont = Frame(self.master)
cont.pack(pady=10, padx=10, fill=BOTH, expand=True)
lable_frame = Frame(cont)
lable_frame.pack(side=TOP, pady=(10, 5))
potion_lable = Label(lable_frame, text="职位:", fg="black")
potion_lable.pack(side=LEFT, padx=5)
self.position = Entry(lable_frame, font=('Verdana', 15), width=10)
self.position.pack(side=LEFT, padx=5)
# an
button_frame = Frame(cont, bg="#96CDCD")
button_frame.pack(side=BOTTOM, pady=(5, 10))
query_button = Button(button_frame, text="查询", fg="black")
query_button.pack(side=LEFT, padx=10)
add_button = Button(button_frame, text="添加发布", fg="black")
add_button.pack(side=LEFT, padx=10)
self.table_frame = Frame(cont)
self.table_frame.pack(side=TOP, fill=X, expand=True)
self.columns = ("name", "position", "salary", "requirement")
self.tree = ttk.Treeview(self.table_frame, show="headings", height=18, columns=self.columns)
self.tree.tag_configure("oddrow", background="#EAEAEA")
self.tree.tag_configure("evenrow", background="#FFFFFF")
# # 表格的标题
self.tree.column("name", width=80, anchor='center')
self.tree.column("position", width=80, anchor='center') # 表示列,不显示
self.tree.column("salary", width=80, anchor='center')
self.tree.column("requirement", width=80, anchor='center')
self.tree.heading('name', text="公司")
self.tree.heading('position', text="职位")
self.tree.heading('salary', text="薪资")
self.tree.heading('requirement', text="要求")
self.tree.pack(pady=10, fill=BOTH, expand=True)
# 定义树形结构与滚动条
vsb = Scrollbar(cont, orient="vertical", command=self.tree.yview)
vsb.pack(side=RIGHT, fill=Y)
hsb = Scrollbar(cont, orient="horizontal", command=self.tree.xview)
hsb.pack(side=BOTTOM, fill=X)
self.tree.configure(yscrollcommand=vsb.set, xscrollcommand=hsb.set)
class scoreClass():
def __init__(self, master):
self.master = master
self.createscore()
def createscore(self):
title_label = Label(self.master, text="这是理系统", font=("Arial", 16))
title_label.pack(pady=10)
# 创建按钮框架
button_frame = Frame(self.master)
button_frame.pack()
# 创建输入框和按钮
input_entry = Entry(button_frame, width=20)
input_entry.pack(side="left", padx=5)
# 创建下拉框
query_button = Button(button_frame, text="查询", width=10)
query_button.pack(side="left", padx=5)
new_button = Button(button_frame, text="新增", width=10)
new_button.pack(side="left", padx=5)
# 创建 Treeview
columns = ("name", "time", "sdept", "class")
self.tree_view = ttk.Treeview(self.master, show='headings', columns=columns, style="Treeview")
self.tree_view.tag_configure("oddrow", background="#EAEAEA")
self.tree_view.tag_configure("evenrow", background="#FFFFFF")
self.tree_view.column("name", width=80, anchor='center')
self.tree_view.column("time", width=80, anchor='center')
self.tree_view.column("sdept", width=80, anchor='center')
self.tree_view.column("class", width=80, anchor='center')
self.tree_view.heading('name', text="姓名")
self.tree_view.heading('time', text="日期")
self.tree_view.heading('sdept', text="任务进度")
self.tree_view.heading('class', text="备注")
self.tree_view.pack(pady=10, fill=BOTH, expand=True)
# 插入示例数据
# 创建空行
empty_row = Label(self.master, text="")
empty_row.pack()
class journalClass():
def __init__(self, master):
self.master = master
self.createjournal()
def createjournal(self):
title_label = Label(self.master, text="这是日志管理系统", font=("Arial", 16))
title_label.pack(pady=10)
# 创建按钮框架
button_frame = Frame(self.master)
button_frame.pack()
# 创建输入框和按钮
input_entry = Entry(button_frame, width=20)
input_entry.pack(side="left", padx=5)
# 创建下拉框
options = ["hjy", "hh", "sb"]
selected_option = StringVar()
selected_option.set(options[0])
edit_combobox = ttk.Combobox(button_frame, textvariable=selected_option, values=options, width=10)
edit_combobox.pack(side="left", padx=5)
query_button = Button(button_frame, text="查询", width=10)
query_button.pack(side="left", padx=5)
new_button = Button(button_frame, text="新增", width=10)
new_button.pack(side="left", padx=5)
# 创建 Treeview
columns = ("name", "time", "sdept", "class")
self.tree_view = ttk.Treeview(self.master, show='headings', columns=columns, style="Treeview")
self.tree_view.tag_configure("oddrow", background="#EAEAEA")
self.tree_view.tag_configure("evenrow", background="#FFFFFF")
self.tree_view.column("name", width=80, anchor='center')
self.tree_view.column("time", width=80, anchor='center')
self.tree_view.column("sdept", width=80, anchor='center')
self.tree_view.column("class", width=80, anchor='center')
self.tree_view.heading('name', text="姓名")
self.tree_view.heading('time', text="日期")
self.tree_view.heading('sdept', text="任务进度")
self.tree_view.heading('class', text="备注")
self.tree_view.pack(pady=10, fill=BOTH, expand=True)
# 插入示例数据
# 创建空行
empty_row = Label(self.master, text="")
empty_row.pack()
class discussClass():
def __init__(self, master):
self.master = master
Label(master, text="这是讨论区管理界面").pack()
root = Tk()
root.geometry("700x500")
frame = Frame(root, width=100, height=500, highlightbackground="#668B8B", highlightthickness=3)
frame.config(background="#96CDCD")
frame.pack(fill=Y, side=LEFT)
bai = Label(frame)
student = Label(frame, text="学生系统", font=("微软雅黑", 14), fg="white", bg="#96CDCD")
student.place(x=5, y=30)
admin = Label(frame, text="招聘系统", font=("微软雅黑", 14), fg="white", bg="#96CDCD")
admin.place(x=5, y=120)
score = Label(frame, text="打分管理", font=("微软雅黑", 14), fg="white", bg="#96CDCD")
score.place(x=5, y=210)
journal = Label(frame, text="日志管理", font=("微软雅黑", 14), fg="white", bg="#96CDCD")
journal.place(x=5, y=300)
discuss = Label(frame, text="讨论区", font=("微软雅黑", 14), fg="white", bg="#96CDCD")
discuss.place(x=5, y=390)
stuFrame = Frame(root)
admFrame = Frame(root)
scoFrame = Frame(root)
jouFrame = Frame(root)
disFrame = Frame(root)
studentClass(stuFrame)
adminClass(admFrame)
scoreClass(scoFrame)
journalClass(jouFrame)
discussClass(disFrame)
def stuFuntion(event=None):
stuFrame.pack(fill=BOTH, expand=True)
admFrame.pack_forget()
scoFrame.pack_forget()
jouFrame.pack_forget()
disFrame.pack_forget()
def admFuntion(event=None):
admFrame.pack()
stuFrame.pack_forget()
scoFrame.pack_forget()
jouFrame.pack_forget()
disFrame.pack_forget()
def scoFuntion(event=None):
scoFrame.pack()
stuFrame.pack_forget()
jouFrame.pack_forget()
disFrame.pack_forget()
admFrame.pack_forget()
def jouFuntion(event=None):
jouFrame.pack()
stuFrame.pack_forget()
disFrame.pack_forget()
admFrame.pack_forget()
scoFrame.pack_forget()
def disFuntion(event=None):
disFrame.pack()
stuFrame.pack_forget()
disFrame.pack_forget()
admFrame.pack_forget()
scoFrame.pack_forget()
student.bind("<Button-1>", stuFuntion)
admin.bind("<Button-1>", admFuntion)
score.bind("<Button-1>", scoFuntion)
journal.bind("<Button-1>", jouFuntion)
discuss.bind("<Button-1>", disFuntion)
root.title("学生管理系统")
root.mainloop()