职业考试的课件及资料包括一级建造师、一级造价师、监理工程师、消防工程师、安全工程师、消防工程师等,很多学习资料都在百度网盘上。因学生需要用pathon开发了一个查询工具。运行结果如图:登录界面
查询结果界面:
下面是代码片段:
import tkinter as tk
from LoginPage import *
root = tk.Tk()
root.title('公众号-建筑课程')
LoginPage(root)
# MainPage(root)
root.mainloop()
第二页:
import tkinter as tk
from view import * # 菜单栏对应的各个子页面
class MainPage(object):
def __init__(self, master=None):
self.root = master # 定义内部变量root
self.root.geometry('%dx%d' % (800, 600)) # 设置窗口大小
self.create_page()
def create_page(self):
menubar = tk.Menu(self.root)
# menubar.add_command(label='录入')
# menubar.add_command(label='查询')
# menubar.add_command(label='删除')
# menubar.add_command(label='修改')
# menubar.add_command(label='关于')
self.input_page = InputFrame(self.root) # 创建不同 Frame
self.query_page = QueryFrame(self.root)
self.delete_page = DeleteFrame(self.root)
self.change_page = ChangeFrame(self.root)
self.about_page = AboutFrame(self.root)
self.query_page.pack() # 默认显示数据录入界面
# 控件只是显示,如果需要实现切换的逻辑需要用代码实现
# menubar.add_command(label='录入', command=self.input_data)
menubar.add_command(label='查询', command=self.query_data)
# menubar.add_command(label='删除', command=self.delete_data)
# menubar.add_command(label='修改', command=self.change_data)
menubar.add_command(label='关于', command=self.about_disc)
self.root['menu'] = menubar # 设置菜单栏
# def input_data(self):
# self.input_page.pack()
# self.query_page.pack_forget()
# self.delete_page.pack_forget()
# self.change_page.pack_forget()
# self.about_page.pack_forget()
def query_data(self):
self.input_page.pack_forget()
# self.query_page.pack(fill="both", expand=1, padx=10, pady=10, anchor=tk.N)
self.delete_page.pack_forget()
self.change_page.pack_forget()
self.about_page.pack_forget()
# def delete_data(self):
# self.input_page.pack_forget()
# self.query_page.pack_forget()
# self.delete_page.pack()
# self.change_page.pack_forget()
# self.about_page.pack_forget()
# def change_data(self):
# self.input_page.pack_forget()
# self.query_page.pack_forget()
# self.delete_page.pack_forget()
# self.change_page.pack()
# self.about_page.pack_forget()
def about_disc(self):
self.input_page.pack_forget()
self.query_page.pack_forget()
self.delete_page.pack_forget()
self.change_page.pack_forget()
self.about_page.pack()
def __del__(self):
db.save_data()
if __name__ == '__main__':
root = tk.Tk()
MainPage(root)
root.mainloop()
第三页:
import tkinter as tk
from tkinter import ttk, LEFT
from db import db
from lax import lax
class InputFrame(tk.Frame): # 继承Frame类
def __init__(self, master=None):
super().__init__(master)
self.root = master # 定义内部变量root
self.name = tk.StringVar()
self.math = tk.StringVar()
self.chinese = tk.StringVar()
self.english = tk.StringVar()
self.status = tk.StringVar()
self.create_page()
def create_page(self):
# stick 控件对象方向 tk.W 西方位
# pady padding y 上下的宽度
# row 行 表格布局
tk.Label(self).grid(row=0, stick=tk.W, pady=10)
tk.Label(self, text='姓 名: ').grid(row=1, stick=tk.W, pady=10)
# text variable 绑定控件里面的数据内容
tk.Entry(self, textvariable=self.name).grid(row=1, column=1, stick=tk.E)
tk.Label(self, text='数 学: ').grid(row=2, stick=tk.W, pady=10)
tk.Entry(self, textvariable=self.math).grid(row=2, column=1, stick=tk.E)
tk.Label(self, text='语 文: ').grid(row=3, stick=tk.W, pady=10)
tk.Entry(self, textvariable=self.chinese).grid(row=3, column=1, stick=tk.E)
tk.Label(self, text='英 语: ').grid(row=4, stick=tk.W, pady=10)
tk.Entry(self, textvariable=self.english).grid(row=4, column=1, stick=tk.E)
tk.Button(self, text='录入', command=self.recode_student).grid(row=5, column=1, stick=tk.E, pady=10)
tk.Label(self, textvariable=self.status).grid(row=6, column=1, stick=tk.E, pady=10)
def recode_student(self):
student = {
'name': self.name.get(),
'math': self.math.get(),
'chinese': self.chinese.get(),
'english': self.english.get(),
}
db.insert(student)
self.status.set('插入数据成功')
self._clear_avr()
def _clear_avr(self):
self.name.set("")
self.math.set("")
self.chinese.set("")
self.english.set("")
class QueryFrame(tk.Frame): # 继承Frame类
def __init__(self, master=None):
super().__init__(master)
self.root = master # 定义内部变量root
self.itemName = tk.StringVar()
self.w=1500
self.h=0
self.table_frame = tk.Frame(self.root,width=self.w,height=self.h)
# self.label = tk.Label(self.table_frame, text="Label", justify=LEFT)
# self.label.pack(side=LEFT)
self.table_frame.pack()
self.row = 1
self.create_page()
def create_page(self):
self.create_tree_view()
self.show_data_frame()
tk.Button(self, text='刷新数据', command=self.show_data_frame).pack(anchor=tk.E, pady=5)
# def show_data_frame(self):
# # 删除原节点
# for _ in map(self.tree_view.delete, self.tree_view.get_children("")):
# pass
# students = db.all()
# for index, stu in enumerate(students):
# print(stu)
# self.tree_view.insert('', index + 1,
# values=(stu['name'], str(stu['chinese']), str(stu['math']), str(stu['english'])))
def show_data_frame(self):
# 删除原节点
for _ in map(self.tree_view.delete, self.tree_view.get_children("")):
pass
students = lax.parse_page(1)
a = 0
for i in range(25):
# a=i
# print(a)
print(students)
# for stu in enumerate(students):
# print(stu)
self.tree_view.insert('',1000,values=(students))
# def create_tree_view(self):
# # 表格
# #
# columns = ("name", "chinese", "math", "english")
# columns_value = ('姓名', '语文', '数学', '英语')
# self.tree_view = ttk.Treeview(self, show="headings", columns=columns)
# self.tree_view.column('name', width=80, anchor='center')
# self.tree_view.column('chinese', width=80, anchor='center')
# self.tree_view.column('math', width=80, anchor='center')
# self.tree_view.column('english', width=80, anchor='center')
# self.tree_view.heading('name', text='姓名')
# self.tree_view.heading('chinese', text='语文')
# self.tree_view.heading('math', text='数学')
# self.tree_view.heading('english', text='英语')
# self.tree_view.pack(fill = tk.BOTH, expand = True)
def create_tree_view(self):
# 表格
#
columns = ("name")
columns_value = ('课件')
self.tree_view = ttk.Treeview(self, height=25,show="headings", columns=columns)
self.tree_view.column('name', width=1500,anchor='center')
# self.tree_view.column('chinese', width=80, anchor='center')
# self.tree_view.column('math', width=80, anchor='center')
# self.tree_view.column('english', width=80, anchor='center')
self.tree_view.heading('name', text='课件资料')
# self.tree_view.heading('chinese', text='语文')
# self.tree_view.heading('math', text='数学')
# self.tree_view.heading('english', text='英语')
self.tree_view.pack(fill = tk.BOTH, expand = True)
# self.tree_view.pack()