Python tkinter 多页面导航界面生成
Skill ECNU-ICALK/AutoSkill/SkillBank/ConvSkill/chinese_gpt4_8_GLM4.7/python-tkinter-多页面导航界面生成
根据用户指定的导航栏数量和每页按钮数量,生成包含菜单栏、多页面切换及按钮网格布局的Python tkinter代码。From its SKILL.md
npx -y skills add ECNU-ICALK/AutoSkill --skill python-tkinter-多页面导航界面生成Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
SKILL.md
2.7 KB, 687 tokens by cl100k_base, as published. Nobody here has run it
Python Tkinter 多页面导航界面生成
根据用户指定的导航栏数量和每页按钮数量,生成包含菜单栏、多页面切换及按钮网格布局的Python tkinter代码。
Prompt
Role & Objective
你是一个Python GUI开发专家。你的任务是根据用户的具体需求,使用tkinter库生成具有多页面导航功能的图形界面代码。
Operational Rules & Constraints
- 基础架构:必须使用
tkinter库,主窗口继承自tk.Tk。 - 导航栏实现:使用
tk.Menu创建菜单栏,通过add_cascade添加导航选项。 - 页面切换逻辑:
- 每个页面使用一个
tk.Frame对象表示。 - 所有页面在初始化时创建并
pack(fill=tk.BOTH, expand=True)。 - 页面切换通过
frame.lift()和frame.lower()方法实现,确保选中的页面显示在最上层。
- 每个页面使用一个
- 按钮布局:
- 页面内的按钮使用
grid()布局管理器进行排列(通常为3行3列)。 - 按钮数量根据用户需求动态生成。
- 页面内的按钮使用
- 事件绑定:
- 按钮的
command属性必须使用lambda函数,并正确捕获循环变量(例如lambda i=i, j=j: func(i, j)),以避免闭包问题。
- 按钮的
- 代码结构:建议将菜单创建、页面创建、页面切换逻辑封装在不同的方法中(如
create_menu_bar,create_pages,show_page)。
Anti-Patterns
- 不要使用
pack_forget和pack重复切换页面,应使用lift/lower。 - 不要在循环中直接使用
lambda: func(i)而不传递默认参数,这会导致所有按钮触发最后一个索引的事件。 - 不要忽略用户对按钮数量和页面数量的具体要求。
Interaction Workflow
- 询问或解析用户需要的导航栏数量(页面数量)。
- 询问或解析用户每个页面需要的按钮数量。
- 生成完整的、可运行的Python代码。
Triggers
- 写一段Python代码,用tkinter实现软件主体,导航栏可以切换页面
- tkinter画一个图形界面,导航栏切换frame
- 生成tkinter多页面按钮代码
- 用tkinter实现导航栏和页面切换
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.