import time from magictk import mtk, color_tmpl from logger.logger import * choose_id = 0 load_lock = False load_timer = 0 anim_added = False def nav_callback(obj): global load_lock, load_timer, anim_added ids = obj.ids side = navlists[ids]["side"] global choose_id, nav_main, lastobj if (choose_id == ids): return if (load_lock == True): return load_timer = 5 # 再小就会出bug load_lock = True if (anim_added == False): def anim_func(*args): global load_lock, load_timer if (load_timer > 0): load_timer -= 1 if (load_timer == 0 and load_lock == True): load_lock = False nav_frame_now.root.anim.append(anim_func) anim_added = True choose_id = ids if (side == "top"): nav_frame_now.place_forget() nav_frame_now.place(x=0, y=50*ids, width=3, height=50, anchor='nw') else: nav_frame_now.place_forget() nav_frame_now.place(x=0, rely=1, width=3, height=50, anchor='sw') lastobj.pack_forget() lastobj = btn_frame_list[choose_id](nav_main) nav_frame_now.root.main_tk.update() def pack_nav(master: mtk.Frame, root: mtk.Frame, navlist: list): global nav_frame_now, btn_list, navlists, nav_main, btn_frame_list, lastobj navlists = navlist nav_frame = mtk.Frame(master) nav_frame_show = mtk.Frame(nav_frame, w=3) nav_frame_now = mtk.Frame( nav_frame_show, w=3, bg=color_tmpl.default_color["primary"]) nav_frame_now.place(x=0, y=0, width=3, height=50) nav_frame_show.pack(side="left", fill='y') mtk.Frame(nav_frame, w=1).pack( side="left", expand=True, fill='y') nav_frame_main = mtk.Frame(nav_frame, w=50) btn_list = [] btn_frame_list = [] ids = 0 for i in navlist: icon = i["icon"] frame = i["frame"] side = i["side"] btn_list.append(mtk.ButtonLight( master=nav_frame_main, color_type="plain", iconname=icon, iconsize=32, w=50, h=50, func=nav_callback)) btn_list[-1].ids = ids btn_list[-1].pack(side=side) btn_frame_list.append(frame) ids += 1 nav_frame_main.pack(side="left", fill='both') mtk.Frame(nav_frame, w=2).pack( side="left", expand=True, fill='y') mtk.Frame(nav_frame, w=1, bg=color_tmpl.default_color["border_light"]).pack( side="left", expand=True, fill='y') nav_frame.pack(side="left", expand=True, fill='y') nav_main = mtk.Frame( master, w=1000) lastobj = btn_frame_list[0](nav_main) nav_main.pack(side="right", fill='both')