import json
from tkinter import *
from tkinter.ttk import *
class WinGUI(Tk):
def __init__(self):
super().__init__()
self.__win()
# 当前页数
self.index = 1
self.total = 1
self.data = []
self.user: json = {}
self.tk_table_m1ef1meg = self.__tk_table_m1ef1meg(self)
self.tk_label_m1ef4id7 = Label(self, text="", anchor="center", )
self.label_config()
self.tk_label_m1ef4id7.place(relx=0.4625, rely=0.9500, relwidth=0.1938, relheight=0.0500)
self.tk_input_query = Entry(self, )
self.tk_input_query.place(relx=0.0000, rely=0.1183, relwidth=0.2500, relheight=0.0500)
self.tk_button_query = Button(self, text="搜索", takefocus=False, )
self.tk_button_query.place(relx=0.2612, rely=0.1183, relwidth=0.0788, relheight=0.0500)
self.tk_button_head = Button(self, text="首页", takefocus=False, )
self.tk_button_head.place(relx=0.6675, rely=0.9500, relwidth=0.0625, relheight=0.0500)
self.tk_button_previous__page = Button(self, text="上一页", takefocus=False, )
self.tk_button_previous__page.place(relx=0.7462, rely=0.9500, relwidth=0.0625, relheight=0.0500)
self.tk_button_next_page = Button(self, text="下一页", takefocus=False, )
self.tk_button_next_page.place(relx=0.8313, rely=0.9500, relwidth=0.0625, relheight=0.0500)
self.tk_button_last = Button(self, text="尾页", takefocus=False, )
self.tk_button_last.place(relx=0.9187, rely=0.9500, relwidth=0.0625, relheight=0.0500)
def __win(self):
self.title("项目名称")
# 设置窗口大小、居中
width, height = 800, 600
screen_width = self.winfo_screenwidth()
screen_height = self.winfo_screenwidth()
geometry = '%dx%d+%d+%d' % (width, height, (screen_width - width) // 2, (screen_height - height) // 2)
self.iconbitmap('favicon.ico')
self.geometry(geometry)
self.minsize(width=width, height=height)
def set_user(self, user: json):
self.user = user
def __tk_table_m1ef1meg(self, parent):
# 表头字段 表头宽度
columns = {"序列": 79, "姓名": 239, "民族": 79, "年龄": 79, "简介": 319}
tk_table = Treeview(parent, show="headings", columns=list(columns), )
for text, width in columns.items(): # 批量设置列属性
tk_table.heading(text, text=text, anchor='center')
tk_table.column(text, anchor='center', width=width, stretch=True) # stretch 不自动拉伸
tk_table.place(relx=0.0000, rely=0.1817, relwidth=0.9988, relheight=0.7500)
return tk_table
def page_add_index(self):
# 下一页
if self.index < self.total:
self.index += 1
return self.index
def page_sub_index(self):
# 上一页
if self.index > 1:
self.index -= 1
return self.index
def label_config(self):
self.tk_label_m1ef4id7.config(text=f"当前第{self.index}页/共{self.total}页")
def update_table(self):
if self.data and len(self.data) > 0:
if self.tk_table_m1ef1meg.get_children():
for get_child in self.tk_table_m1ef1meg.get_children():
self.tk_table_m1ef1meg.delete(get_child)
for index, datum in enumerate(self.data):
self.tk_table_m1ef1meg.insert("", "end", text='',
values=(
index + 1, datum.get('name', ''), datum.get('nation', ''),
datum.get('age', ''), datum.get('info', '')))
class Win(WinGUI):
def __init__(self, controller):
self.ctl = controller
super().__init__()
self.__event_bind()
self.__style_config()
self.config(menu=self.create_menu())
self.ctl.init(self)
def create_menu(self):
menu = Menu(self, tearoff=False)
menu.add_cascade(label="设置", menu=self.menu_m1ecaoyu(menu))
menu.add_cascade(label="帮助", menu=self.menu_m1eccdqt(menu))
return menu
def menu_m1ecaoyu(self, parent):
menu = Menu(parent, tearoff=False)
menu.add_command(label="关闭界面", command=self.ctl.close_windows)
return menu
def menu_m1eccdqt(self, parent):
menu = Menu(parent, tearoff=False)
menu.add_command(label="版本信息", command=self.ctl.version)
return menu
def __event_bind(self):
self.tk_input_query.bind('<Return>', self.ctl.select_member_data)
self.tk_button_query.bind('<Button-1>', self.ctl.select_member_data)
self.tk_button_head.bind('<Button-1>', lambda event: self.ctl.load_member_data_next(self.index))
self.tk_button_last.bind('<Button-1>', lambda event: self.ctl.load_member_data_next(self.total))
self.tk_button_previous__page.bind('<Button-1>',
lambda event: self.ctl.load_member_data_next(self.page_sub_index()))
self.tk_button_next_page.bind('<Button-1>', lambda event: self.ctl.load_member_data_next(self.page_add_index()))
pass
def __style_config(self):
pass
if __name__ == "__main__":
win = WinGUI()
win.mainloop()
07-13
627
06-13
5163
08-14
8899
06-06
619