|
|
@ -22,8 +22,9 @@ class LoadElement(Frame):
|
|
|
|
self.master = master
|
|
|
|
self.master = master
|
|
|
|
self.table_name = table_name
|
|
|
|
self.table_name = table_name
|
|
|
|
self.data = []
|
|
|
|
self.data = []
|
|
|
|
self.conn = pymysql.connect(user="root", password="cyh0110", database="SCT", host="127.0.0.1", port=3306)
|
|
|
|
self.conn = pymysql.connect(user="root", password="123123", database="stu_sys", host="127.0.0.1", port=3306)
|
|
|
|
self.data_frame = pd.read_sql(f"select * from {self.table_name} limit 0", self.conn)
|
|
|
|
self.data_frame = pd.read_sql(f"select * from {self.table_name} limit 0", self.conn)
|
|
|
|
|
|
|
|
#左侧三框框数据
|
|
|
|
self.font_style = tkFont.Font(family="Lucida Grande", size=20)
|
|
|
|
self.font_style = tkFont.Font(family="Lucida Grande", size=20)
|
|
|
|
self.button_font = tkFont.Font(family="Lucida Grande", size=10)
|
|
|
|
self.button_font = tkFont.Font(family="Lucida Grande", size=10)
|
|
|
|
self.create_widget()
|
|
|
|
self.create_widget()
|
|
|
@ -46,11 +47,11 @@ class LoadElement(Frame):
|
|
|
|
combo["values"] = tables
|
|
|
|
combo["values"] = tables
|
|
|
|
combo.bind('<<ComboboxSelected>>', self.select_value)
|
|
|
|
combo.bind('<<ComboboxSelected>>', self.select_value)
|
|
|
|
combo.grid(column=0, row=0)
|
|
|
|
combo.grid(column=0, row=0)
|
|
|
|
Button(self, text="装载", width=10, command=self.load).grid(column=1, row=0, padx=5)
|
|
|
|
Button(self, text="装载", width=9, command=self.load).grid(column=1, row=0, padx=5)
|
|
|
|
|
|
|
|
|
|
|
|
def create_tree_widget(self):
|
|
|
|
def create_tree_widget(self):
|
|
|
|
# 创建画布,用于展示装载后的数据
|
|
|
|
# 创建画布,用于展示装载后的数据
|
|
|
|
frame = Frame(self, width=50, height=180)
|
|
|
|
frame = Frame(self, width=50, height=250)
|
|
|
|
frame.grid(row=1, column=0, columnspan=2, sticky=NSEW, pady=5)
|
|
|
|
frame.grid(row=1, column=0, columnspan=2, sticky=NSEW, pady=5)
|
|
|
|
frame.grid_columnconfigure(0, weight=1)
|
|
|
|
frame.grid_columnconfigure(0, weight=1)
|
|
|
|
frame.grid_rowconfigure(0, weight=1)
|
|
|
|
frame.grid_rowconfigure(0, weight=1)
|
|
|
@ -83,12 +84,13 @@ class LoadElement(Frame):
|
|
|
|
self.create_tree_widget()
|
|
|
|
self.create_tree_widget()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class FormElement(Frame):
|
|
|
|
class FormElement(Frame):
|
|
|
|
def __init__(self, master, node):
|
|
|
|
def __init__(self, master, node):
|
|
|
|
super().__init__(master)
|
|
|
|
super().__init__(master)
|
|
|
|
self.node = node
|
|
|
|
self.node = node
|
|
|
|
self.data = []
|
|
|
|
self.data = []
|
|
|
|
self.conn = pymysql.connect(user="root", password="cyh0110", database="SCT", host="127.0.0.1", port=3306)
|
|
|
|
self.conn = pymysql.connect(user="root", password="123123", database="stu_sys", host="127.0.0.1", port=3306)
|
|
|
|
self.font_style = tkFont.Font(family="Lucida Grande", size=20)
|
|
|
|
self.font_style = tkFont.Font(family="Lucida Grande", size=20)
|
|
|
|
self.button_font = tkFont.Font(family="Lucida Grande", size=10)
|
|
|
|
self.button_font = tkFont.Font(family="Lucida Grande", size=10)
|
|
|
|
self.table_names = []
|
|
|
|
self.table_names = []
|
|
|
@ -100,14 +102,6 @@ class FormElement(Frame):
|
|
|
|
self.select_table(None)
|
|
|
|
self.select_table(None)
|
|
|
|
self.create_treeview(pd.read_sql(self.default_query_sql, con=self.conn))
|
|
|
|
self.create_treeview(pd.read_sql(self.default_query_sql, con=self.conn))
|
|
|
|
|
|
|
|
|
|
|
|
def get_table_names(self):
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
获取该数据库下所有的表
|
|
|
|
|
|
|
|
:return:
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
data_frame = pd.read_sql("show tables", self.conn)
|
|
|
|
|
|
|
|
self.table_names = [i[0] for i in data_frame.values.tolist()]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def select_table(self, event):
|
|
|
|
def select_table(self, event):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
当下拉框选择表之后,触发该函数,并将tableName改为选择的tableName
|
|
|
|
当下拉框选择表之后,触发该函数,并将tableName改为选择的tableName
|
|
|
@ -124,13 +118,27 @@ class FormElement(Frame):
|
|
|
|
self.sql_text.delete(0.0, END)
|
|
|
|
self.sql_text.delete(0.0, END)
|
|
|
|
self.sql_text.insert(1.0, f"SELECT * FROM {self.table_name}")
|
|
|
|
self.sql_text.insert(1.0, f"SELECT * FROM {self.table_name}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_table_names(self):
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
获取该数据库下所有的表
|
|
|
|
|
|
|
|
:return:
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
data_frame = pd.read_sql("show tables", self.conn)
|
|
|
|
|
|
|
|
self.table_names = [i[0] for i in data_frame.values.tolist()]
|
|
|
|
|
|
|
|
|
|
|
|
def get_field_names(self):
|
|
|
|
def get_field_names(self):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
获取所有数据表的所有字段
|
|
|
|
获取所有数据表的所有字段
|
|
|
|
:return: 返回表内的所有字段
|
|
|
|
:return: 返回表内的所有字段
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
data_frame = pd.read_sql(f"desc {self.table_name}", self.conn)
|
|
|
|
data_frame = pd.read_sql(f"desc {self.table_name}", self.conn)
|
|
|
|
return data_frame["Field"].tolist()
|
|
|
|
"""
|
|
|
|
|
|
|
|
field_names = []
|
|
|
|
|
|
|
|
for field in data_frame["Field"]:
|
|
|
|
|
|
|
|
field_names.append(f"{self.table_name}.{field}")
|
|
|
|
|
|
|
|
return field_names
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
return data_frame["Field"].values.tolist()
|
|
|
|
|
|
|
|
|
|
|
|
def create_form(self):
|
|
|
|
def create_form(self):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
@ -139,7 +147,7 @@ class FormElement(Frame):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
self.select_table_name = StringVar()
|
|
|
|
self.select_table_name = StringVar()
|
|
|
|
self.select_table_name.set(self.table_name)
|
|
|
|
self.select_table_name.set(self.table_name)
|
|
|
|
combo = ttk.Combobox(self, width=10, height=1, textvariable=self.select_table_name, font=self.font_style,
|
|
|
|
combo = ttk.Combobox(self, width=8, height=1, textvariable=self.select_table_name, font=self.font_style,
|
|
|
|
style="TCombobox")
|
|
|
|
style="TCombobox")
|
|
|
|
combo["values"] = self.table_names
|
|
|
|
combo["values"] = self.table_names
|
|
|
|
combo.bind('<<ComboboxSelected>>', self.select_table)
|
|
|
|
combo.bind('<<ComboboxSelected>>', self.select_table)
|
|
|
@ -158,7 +166,7 @@ class FormElement(Frame):
|
|
|
|
checkbutton_var = IntVar()
|
|
|
|
checkbutton_var = IntVar()
|
|
|
|
checkbutton = Checkbutton(self, text='', variable=checkbutton_var)
|
|
|
|
checkbutton = Checkbutton(self, text='', variable=checkbutton_var)
|
|
|
|
checkbutton.grid(row=i + 1, column=j * 2, padx=5, pady=5, sticky=E)
|
|
|
|
checkbutton.grid(row=i + 1, column=j * 2, padx=5, pady=5, sticky=E)
|
|
|
|
entry = Entry(self, font=self.font_style)
|
|
|
|
entry = Entry(self, font=self.font_style,width=12)
|
|
|
|
entry.grid(row=i + 1, column=j * 2 + 1, padx=5, pady=5, sticky=W)
|
|
|
|
entry.grid(row=i + 1, column=j * 2 + 1, padx=5, pady=5, sticky=W)
|
|
|
|
self.form_content[field_name] = (entry, checkbutton_var, label, checkbutton)
|
|
|
|
self.form_content[field_name] = (entry, checkbutton_var, label, checkbutton)
|
|
|
|
style = Style()
|
|
|
|
style = Style()
|
|
|
@ -166,7 +174,7 @@ class FormElement(Frame):
|
|
|
|
Button(self, text="构造SQL", command=self.make_sql, width=8, style="custom.TButton"
|
|
|
|
Button(self, text="构造SQL", command=self.make_sql, width=8, style="custom.TButton"
|
|
|
|
).grid(column=8, row=0, rowspan=8)
|
|
|
|
).grid(column=8, row=0, rowspan=8)
|
|
|
|
|
|
|
|
|
|
|
|
self.sql_text = Text(self, height=3, font=self.font_style, width=75)
|
|
|
|
self.sql_text = Text(self, height=3, font=self.font_style, width=46)
|
|
|
|
self.sql_text.grid(row=8, column=0, rowspan=2, columnspan=7, sticky=W)
|
|
|
|
self.sql_text.grid(row=8, column=0, rowspan=2, columnspan=7, sticky=W)
|
|
|
|
Button(self, text="\n执行SQL\n", command=self.execute_sql, width=8,
|
|
|
|
Button(self, text="\n执行SQL\n", command=self.execute_sql, width=8,
|
|
|
|
).grid(column=8, row=8, rowspan=2, padx=10)
|
|
|
|
).grid(column=8, row=8, rowspan=2, padx=10)
|
|
|
@ -195,8 +203,11 @@ class FormElement(Frame):
|
|
|
|
frame.grid(row=10, column=0, columnspan=10, rowspan=5, sticky=NSEW, pady=10)
|
|
|
|
frame.grid(row=10, column=0, columnspan=10, rowspan=5, sticky=NSEW, pady=10)
|
|
|
|
frame.grid_columnconfigure(0, weight=1)
|
|
|
|
frame.grid_columnconfigure(0, weight=1)
|
|
|
|
frame.grid_rowconfigure(0, weight=1)
|
|
|
|
frame.grid_rowconfigure(0, weight=1)
|
|
|
|
columns = data_frame.keys().tolist()
|
|
|
|
unique_columns = data_frame.columns[~data_frame.columns.duplicated()]
|
|
|
|
tree = ttk.Treeview(frame, columns=columns, show="headings", style="mystyle.Treeview", height=50, selectmode=BROWSE)
|
|
|
|
columns = unique_columns.tolist()
|
|
|
|
|
|
|
|
# 获取查询的列名,将其转换为列表
|
|
|
|
|
|
|
|
tree = ttk.Treeview(frame, columns=columns, show="headings", style="mystyle.Treeview", height=50,
|
|
|
|
|
|
|
|
selectmode=BROWSE)
|
|
|
|
style = ttk.Style()
|
|
|
|
style = ttk.Style()
|
|
|
|
style.configure("Treeview.Heading", font=self.font_style)
|
|
|
|
style.configure("Treeview.Heading", font=self.font_style)
|
|
|
|
style.configure("Treeview", rowheight=30, font=self.font_style, borderwidth=1)
|
|
|
|
style.configure("Treeview", rowheight=30, font=self.font_style, borderwidth=1)
|
|
|
@ -229,7 +240,6 @@ class FormElement(Frame):
|
|
|
|
self.sql_text.delete(0.0, END)
|
|
|
|
self.sql_text.delete(0.0, END)
|
|
|
|
self.sql_text.insert(1.0, sql)
|
|
|
|
self.sql_text.insert(1.0, sql)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class StuSys_X4(BaseWindow):
|
|
|
|
class StuSys_X4(BaseWindow):
|
|
|
|
def __init__(self, master, attr):
|
|
|
|
def __init__(self, master, attr):
|
|
|
|
super().__init__(master, attr)
|
|
|
|
super().__init__(master, attr)
|
|
|
@ -239,6 +249,8 @@ class StuSys_X4(BaseWindow):
|
|
|
|
|
|
|
|
|
|
|
|
def create_left_plate(self):
|
|
|
|
def create_left_plate(self):
|
|
|
|
self.left_frame = Frame(self.master, height=self.attr["height"])
|
|
|
|
self.left_frame = Frame(self.master, height=self.attr["height"])
|
|
|
|
|
|
|
|
self.right_frame = Frame(self.master, height=self.attr["height"])
|
|
|
|
|
|
|
|
self.right_frame.pack(side=RIGHT, anchor=NW, pady=10, padx=10)
|
|
|
|
self.left_frame.pack(side=LEFT, anchor=NW, pady=10, padx=10)
|
|
|
|
self.left_frame.pack(side=LEFT, anchor=NW, pady=10, padx=10)
|
|
|
|
load_element1 = LoadElement(self.left_frame, "student")
|
|
|
|
load_element1 = LoadElement(self.left_frame, "student")
|
|
|
|
load_element1.pack(side=TOP, pady=10)
|
|
|
|
load_element1.pack(side=TOP, pady=10)
|
|
|
@ -246,9 +258,9 @@ class StuSys_X4(BaseWindow):
|
|
|
|
load_element2.pack(side=TOP, pady=10)
|
|
|
|
load_element2.pack(side=TOP, pady=10)
|
|
|
|
load_element2 = LoadElement(self.left_frame, "sc")
|
|
|
|
load_element2 = LoadElement(self.left_frame, "sc")
|
|
|
|
load_element2.pack(side=TOP, pady=10)
|
|
|
|
load_element2.pack(side=TOP, pady=10)
|
|
|
|
message_frame = Frame(self.left_frame, width=50, height=180)
|
|
|
|
message_frame = Frame(self.right_frame, width=50, height=180)
|
|
|
|
message_frame.pack(side=TOP, pady=10, fill=BOTH)
|
|
|
|
message_frame.pack(side=TOP, pady=10, fill=BOTH)
|
|
|
|
self.canvas = Canvas(message_frame, width=50, height=180, bg="#f0f5fa")
|
|
|
|
self.canvas = Canvas(message_frame, width=280, height=1000, bg="#f0f5fa")
|
|
|
|
self.canvas.configure(background="#f0f5fa")
|
|
|
|
self.canvas.configure(background="#f0f5fa")
|
|
|
|
y_scrollbar = Scrollbar(message_frame, orient="vertical", command=self.canvas.yview)
|
|
|
|
y_scrollbar = Scrollbar(message_frame, orient="vertical", command=self.canvas.yview)
|
|
|
|
x_scrollbar = Scrollbar(message_frame, orient="horizontal", command=self.canvas.xview)
|
|
|
|
x_scrollbar = Scrollbar(message_frame, orient="horizontal", command=self.canvas.xview)
|
|
|
@ -263,7 +275,8 @@ class StuSys_X4(BaseWindow):
|
|
|
|
for message in self.message:
|
|
|
|
for message in self.message:
|
|
|
|
index = self.message.index(message)
|
|
|
|
index = self.message.index(message)
|
|
|
|
self.canvas.create_text(0, 20 * index, anchor="nw",
|
|
|
|
self.canvas.create_text(0, 20 * index, anchor="nw",
|
|
|
|
text=message.split("-")[0], font=("", 15), fill="black" if message.split("-")[-1] == "true" else "red")
|
|
|
|
text=message.split("-")[0], font=("", 15),
|
|
|
|
|
|
|
|
fill="black" if message.split("-")[-1] == "true" else "red")
|
|
|
|
self.canvas.update()
|
|
|
|
self.canvas.update()
|
|
|
|
self.canvas.configure(scrollregion=self.canvas.bbox("all"))
|
|
|
|
self.canvas.configure(scrollregion=self.canvas.bbox("all"))
|
|
|
|
|
|
|
|
|
|
|
@ -273,16 +286,15 @@ class StuSys_X4(BaseWindow):
|
|
|
|
form_element = FormElement(self.right_frame, self)
|
|
|
|
form_element = FormElement(self.right_frame, self)
|
|
|
|
form_element.pack(side=TOP, pady=10, anchor=NE)
|
|
|
|
form_element.pack(side=TOP, pady=10, anchor=NE)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
if __name__ == '__main__':
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
minty, lumen, sandstone, yeti, pulse, united, morph, journal, darkly, superhero, solar
|
|
|
|
minty, lumen, sandstone, yeti, pulse, united, morph, journal, darkly, superhero, solar
|
|
|
|
cyborg, vapor, simplex, cerculean,
|
|
|
|
cyborg, vapor, simplex, cerculean,
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
from pycallgraph2 import PyCallGraph
|
|
|
|
# from pycallgraph2 import PyCallGraph
|
|
|
|
from pycallgraph2.output import GraphvizOutput
|
|
|
|
# from pycallgraph2.output import GraphvizOutput
|
|
|
|
from pycallgraph2 import Config
|
|
|
|
# from pycallgraph2 import Config
|
|
|
|
from pycallgraph2 import GlobbingFilter
|
|
|
|
# from pycallgraph2 import GlobbingFilter
|
|
|
|
style = "morph"
|
|
|
|
style = "morph"
|
|
|
|
root = Window(themename=style)
|
|
|
|
root = Window(themename=style)
|
|
|
|
screenwidth = root.winfo_screenwidth()
|
|
|
|
screenwidth = root.winfo_screenwidth()
|
|
|
@ -290,23 +302,14 @@ if __name__ == '__main__':
|
|
|
|
root.columnconfigure(0, weight=1)
|
|
|
|
root.columnconfigure(0, weight=1)
|
|
|
|
root.rowconfigure(1, weight=1)
|
|
|
|
root.rowconfigure(1, weight=1)
|
|
|
|
root_attr = {
|
|
|
|
root_attr = {
|
|
|
|
"width": screenwidth * 0.83,
|
|
|
|
"width": screenwidth * 0.88,
|
|
|
|
"height": screenheight * 0.85,
|
|
|
|
"height": screenheight * 0.90,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
alignstr = '%dx%d+%d+%d' % (root_attr['width'], root_attr['height'], (screenwidth - root_attr['width']) / 2,
|
|
|
|
alignstr = '%dx%d+%d+%d' % (root_attr['width'], root_attr['height'], (screenwidth - root_attr['width']) / 2,
|
|
|
|
(screenheight - root_attr['height']) / 2)
|
|
|
|
(screenheight - root_attr['height']) / 2)
|
|
|
|
root.geometry(alignstr)
|
|
|
|
root.geometry(alignstr)
|
|
|
|
root.resizable(width=False, height=False)
|
|
|
|
root.resizable(width=False, height=False)
|
|
|
|
output = GraphvizOutput(font_size=30)
|
|
|
|
|
|
|
|
output.output_file = "basic.png"
|
|
|
|
app = StuSys_X4(root, root_attr)
|
|
|
|
output.group_font_size = 40
|
|
|
|
ttk.Style().configure("TButton", font="-size 18")
|
|
|
|
config = Config()
|
|
|
|
|
|
|
|
config.trace_filter = GlobbingFilter(include=[
|
|
|
|
|
|
|
|
'StuSys_X4.*',
|
|
|
|
|
|
|
|
'FormElement.*',
|
|
|
|
|
|
|
|
'LoadElement.*',
|
|
|
|
|
|
|
|
])
|
|
|
|
|
|
|
|
with PyCallGraph(output=output, config=config):
|
|
|
|
|
|
|
|
app = StuSys_X4(root, root_attr)
|
|
|
|
|
|
|
|
ttk.Style().configure("TButton", font="-size 18")
|
|
|
|
|
|
|
|
root.mainloop()
|
|
|
|
root.mainloop()
|
|
|
|