# -*- coding: utf-8 -*- """修界面:卡片根本没显示出来。 我写的 _card() 是这样的: def _card(self, parent): outer = tk.Frame(parent, bg=BORDER) # 外层:边框色 inner = tk.Frame(outer, bg=CARD) # 内层:白底 inner.pack(fill="both", expand=True, padx=1, pady=1) # 挂到 outer return inner # ← 返回内层 调用处:card = self._card(page); card.pack(...) card.pack() 是 inner.pack(),而 inner 的父控件是 **outer** —— 所以它被挂回 outer,而 **outer 从来没有被 pack 进 page**。 结果:两张卡片完全看不见,窗口高度只有 199px, 但控件都"存在"(walk 能列出来),测试也就查不出来。 修法:_card 返回 outer,调用处 pack outer。 """ from __future__ import annotations import ast import sys from pathlib import Path UI = Path(r"C:\Users\shu\Desktop\deepseekagent\LanRemote\windows\lanremote" r"\ui.py") OLD = ''' def _card(self, parent) -> tk.Frame: """一个白底圆角感的卡片(tkinter 没有圆角,用边框色模拟)。""" outer = tk.Frame(parent, bg=BORDER) inner = tk.Frame(outer, bg=CARD) inner.pack(fill="both", expand=True, padx=1, pady=1) return inner''' NEW = ''' def _card(self, parent) -> tk.Frame: """一个白底圆角感的卡片(tkinter 没有圆角,用边框色模拟)。 返回的是**外层** frame —— 调用处要 pack 它。 踩过的坑:一开始返回 inner,而 inner 的父控件是 outer, 于是 inner.pack() 挂回 outer,outer 自己从没被 pack, 结果卡片完全不显示(窗口高度只剩 199px)。 """ outer = tk.Frame(parent, bg=BORDER) inner = tk.Frame(outer, bg=CARD) inner.pack(fill="both", expand=True, padx=1, pady=1) return outer''' # 卡片内容要挂在 inner 上,所以取 inner CARD_USE_OLD = ''' card = self._card(page) card.pack(fill="x", pady=(16, 0)) inner = tk.Frame(card, bg=CARD) inner.pack(fill="x", padx=16, pady=14) ''' CARD_USE_NEW = ''' card = self._card(page) card.pack(fill="x", pady=(16, 0)) inner = tk.Frame(card.winfo_children()[0], bg=CARD) inner.pack(fill="x", padx=16, pady=14) ''' OPTIONS_OLD = ''' options = self._card(page) options.pack(fill="x", pady=(12, 0)) opt_inner = tk.Frame(options, bg=CARD) opt_inner.pack(fill="x", padx=16, pady=12)''' OPTIONS_NEW = ''' options = self._card(page) options.pack(fill="x", pady=(12, 0)) opt_inner = tk.Frame(options.winfo_children()[0], bg=CARD) opt_inner.pack(fill="x", padx=16, pady=12)''' def main() -> int: text = UI.read_text(encoding="utf-8") ok = True if "返回的是**外层** frame" in text: print(" 已经修过") return 0 for old, new, label in ((OLD, NEW, "_card 返回外层"), (CARD_USE_OLD, CARD_USE_NEW, "配对码卡片内容挂 inner"), (OPTIONS_OLD, OPTIONS_NEW, "选项卡片内容挂 inner")): if old in text: text = text.replace(old, new, 1) print(f" {label}") else: print(f" [失败] {label} —— 锚点没找到") ok = False UI.write_text(text, encoding="utf-8", newline="\n") ast.parse(text) print(" ui.py 语法 OK") return 0 if ok else 1 if __name__ == "__main__": sys.exit(main())