diff --git a/douyin/core/douyin_fudai.py b/douyin/core/douyin_fudai.py index d64f2ae..bbcd3be 100644 --- a/douyin/core/douyin_fudai.py +++ b/douyin/core/douyin_fudai.py @@ -2879,7 +2879,9 @@ class fudai_analyse: result="参与失败", ) # 参与失败,增加连续失败计数器 - self._consecutive_attend_failures = getattr(self, "_consecutive_attend_failures", 0) + 1 + self._consecutive_attend_failures = ( + getattr(self, "_consecutive_attend_failures", 0) + 1 + ) # 清除第一次读取标志,下次打开新福袋时重新识别 try: diff --git a/gui/gui_app.py b/gui/gui_app.py index 284803f..be98426 100644 --- a/gui/gui_app.py +++ b/gui/gui_app.py @@ -2760,7 +2760,7 @@ def main(): # 将运行时映射表加入右侧 Notebook mapping_tab = ttk.Frame(notebook) map_box = ttk.LabelFrame(mapping_tab, text="运行时映射表(包含福袋详情)") - map_box.pack(fill=X, padx=10, pady=(10, 10)) + map_box.pack(fill=BOTH, expand=True, padx=10, pady=(10, 10)) map_ctrl = ttk.Frame(map_box) map_ctrl.pack(fill=X, padx=10, pady=(8, 6)) @@ -2834,7 +2834,9 @@ def main(): try: import tkinter.font as tkfont - def _adjust_mapping_tree_columns(tree: ttk.Treeview, padding: int = 12, max_width: int = 1200) -> None: + def _adjust_mapping_tree_columns( + tree: ttk.Treeview, padding: int = 12, max_width: int = 1200 + ) -> None: try: font = tkfont.Font() except Exception: @@ -2896,9 +2898,12 @@ def main(): tree.column(col, width=target) except Exception: pass + except Exception: # tkinter.font 不可用时跳过自动调整 - def _adjust_mapping_tree_columns(tree: ttk.Treeview, padding: int = 12, max_width: int = 1200) -> None: + def _adjust_mapping_tree_columns( + tree: ttk.Treeview, padding: int = 12, max_width: int = 1200 + ) -> None: return map_scroll_y = ttk.Scrollbar( @@ -2919,6 +2924,33 @@ def main(): map_scroll_y.grid(row=0, column=1, sticky="ns") map_scroll_x.grid(row=1, column=0, sticky="ew") + # 绑定窗口变化:自动调整列宽以适配内容(节流,避免频繁计算) + mapping_tree_autofit_job = {"id": None} + + def _schedule_mapping_tree_autofit(_event: object | None = None) -> None: + try: + job_id = mapping_tree_autofit_job.get("id") + if job_id: + root.after_cancel(job_id) + except Exception: + pass + + def _do_adjust() -> None: + try: + _adjust_mapping_tree_columns(mapping_tree) + except Exception: + pass + + try: + mapping_tree_autofit_job["id"] = root.after(120, _do_adjust) + except Exception: + _do_adjust() + + try: + mapping_tree_box.bind("", _schedule_mapping_tree_autofit) + except Exception: + pass + # 加载映射表到表格(尝试多个可能的路径) def _load_mapping_to_view(): # 清空表格 @@ -3193,9 +3225,12 @@ def main(): # 如果已找到并填充了映射表,尝试自动调整列宽以适配内容 if found: try: - _adjust_mapping_tree_columns(mapping_tree) + _schedule_mapping_tree_autofit() except Exception: - pass + try: + _adjust_mapping_tree_columns(mapping_tree) + except Exception: + pass if not found: mapping_source_var.set("未找到 room_pos_map.json")