Repository navigation
0.2.25 程心自定义窗口优先挂到宿主根窗口,避免多出空白 tk 窗口 - #41
Merged
Merged
Conversation
主面板、编辑窗口、打包窗口原先直接 tkinter.Toplevel(),依赖进程里刚好已有 tk 根窗口。宿主在没有根窗口的环境下运行(system.proc_mode = webUI, enable_gui 为假)时,tkinter 会隐式创建一个标题为 tk 的空白根窗口, 这些窗口成为它的子窗口:关它们它留着,关它窗口一起消失。 - GUI.py 新增 resolve_host_root(),经 Proc.get_main_root() 取宿主 main_tk - 新增 create_window():有根窗口就 Toplevel(master),没有就 Tk() 自己当主窗口 - 主面板 start() 与编辑/打包窗口 start() 改用 create_window()
Reviewer's Guide本次 PR 通过统一顶层窗口创建路径,将窗口优先挂载到宿主提供的 main_tk,并为 webUI 或无根窗口环境提供默认根窗口复用及 Tk 兜底,从而消除额外空白 tk 窗口及错误的窗口销毁联动;同时更新发布版本标识。 Sequence diagram for host-aware window creationsequenceDiagram
participant Caller as ChanceCustom窗口
participant Factory as create_window
participant Resolver as resolve_host_root
participant Proc as globalProc
participant Tk as tkinter
Caller->>Factory: create_window()
Factory->>Resolver: resolve_host_root()
Resolver->>Proc: get_main_root()
alt 宿主提供可用根窗口
Proc-->>Resolver: main_tk
Resolver-->>Factory: main_tk
Factory->>Tk: Toplevel(main_tk)
Tk-->>Caller: 子窗口
else 无宿主根窗口
Resolver-->>Factory: None
Factory->>Tk: _default_root
alt 已存在默认根窗口
Tk-->>Factory: default_root
Factory->>Tk: Toplevel(default_root)
Tk-->>Caller: 子窗口
else 无默认根窗口或根窗口不可用
Factory->>Tk: Tk()
Tk-->>Caller: 主窗口
end
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
按 OlivaDiceNativeGUI 同款评审意见对齐实现: - 取根窗口时比较解释器:宿主 main_tk 与 tkinter._default_root 不是同一个 Tk 时 以 _default_root 为准,避免控件与未指定 master 的 StringVar/BooleanVar 分属 两个 Tcl 解释器(初始化失败或取值不生效) - 宿主没有根窗口时不再让窗口自己当根窗口,改为懒加载一个 withdraw() 的隐藏根, 主面板/编辑窗口/打包窗口都是它的 Toplevel:互为兄弟,关一个不带走另一个, 也不会出现可见的空白 tk 窗口
lunzhiPenxil
approved these changes
Oct 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
宿主在没有 tk 根窗口的环境中运行(
system.proc_mode = webUI,此时pluginAPI的enable_gui为假,插件进程不会创建隐藏的main_tk)时,打开「程心自定义」面板:tk的空白窗口tk窗口不跟着关tk窗口,面板跟着一起消失编辑窗口、打包窗口同样使用裸
Toplevel(),产生相同的空白根窗口。终端模式(进程里有
main_tk)不出现该现象,所以只在 webUI 模式复现。原因
ChanceCustom/GUI.py里三处顶层窗口都是:tkinter.Toplevel()不传 master 时会取tkinter._default_root;当进程里还没有根窗口时,tkinter.BaseWidget._setup()会隐式创建Tk()——标题默认就是tk,窗口成为它的子窗口。于是关窗口时根窗口仍在,关根窗口时destroy()连带销毁所有子窗口。实测(CPython 3.12):
宿主提供了标准入口
Proc.get_main_root()(即Proc_data['main_tk']),这里没有使用,也没有兜底分支。改动
resolve_host_root():经Proc.get_main_root()取宿主根窗口,取不到返回Nonecreate_window():优先挂宿主根窗口,其次复用已存在的_default_root,都没有则tkinter.Tk()自己当主窗口start()、编辑窗口start()、打包窗口start()全部改用create_window()验证
flake8通过;ruff check没有引入新的告警(文件里既有的 UP/B 类告警未改动)兼容性
main_tk上tk窗口get_main_root的旧版本会走_default_root/Tk()分支,不会报错Summary by Sourcery
为程心自定义的各类界面统一管理 Tk 根窗口,避免无头环境产生多余空白窗口。
Bug Fixes:
Enhancements:
Chores: