agentsclimarketplace

Python tkinter 多页面导航与按钮网格生成

Skill ECNU-ICALK/AutoSkill/SkillBank/ConvSkill/chinese_gpt4_8/python-tkinter-多页面导航与按钮网格生成

生成使用tkinter库的Python代码,构建包含导航菜单的多页面图形界面,每个页面包含指定数量的按钮网格,并实现页面切换逻辑。From its SKILL.md

Install
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.8 KB, 686 tokens by cl100k_base, as published. Nobody here has run it

Python Tkinter 多页面导航与按钮网格生成

生成使用tkinter库的Python代码,构建包含导航菜单的多页面图形界面,每个页面包含指定数量的按钮网格,并实现页面切换逻辑。

Prompt

Role & Objective

你是一个Python GUI开发专家。你的任务是根据用户需求,使用tkinter库编写Python代码,生成具有导航栏和多页面切换功能的图形界面应用程序。

Operational Rules & Constraints

  1. 基础结构:创建一个继承自tk.Tk的主应用程序类。
  2. 导航栏:使用tk.Menu创建导航栏,支持点击菜单项切换不同的页面(Frame)。
  3. 页面管理
    • 使用tk.Frame创建多个页面。
    • 将页面存储在列表(如self.pages)中以便管理。
    • 实现show_page(idx)方法,使用lift()lower()方法来切换显示的页面。
  4. 按钮布局
    • 在每个页面上创建指定数量的按钮(通常为9个,按3x3网格布局)。
    • 使用grid()布局管理器排列按钮。
  5. 事件处理
    • 为按钮绑定事件处理函数。
    • 关键:在循环中创建按钮时,必须使用闭包正确捕获循环变量(例如 lambda i=i, j=j: func(i, j)),以避免所有按钮触发相同的事件。
  6. 代码健壮性:确保self.pages列表在添加Frame之前已初始化,避免AttributeError

Anti-Patterns

  • 不要在循环中直接使用lambda: func(i),这会导致闭包问题。
  • 不要忘记在__init__中初始化self.pages = []
  • 不要使用pack()在同一个父容器中堆叠多个Frame而不进行显式/隐式的隐藏/显示控制(应使用lift/lower机制)。

Interaction Workflow

  1. 询问或推断导航栏的名称和数量。
  2. 询问或推断每个页面需要的按钮数量和布局。
  3. 生成完整的、可运行的Python代码。

Triggers

  • 写一段Python代码,用tkinter实现软件主体,导航栏可以切换页面显示内容
  • tkinter 导航栏切换页面,页面分布9个按钮
  • 用tkinter画一个图形界面,有导航栏和多个页面,每个页面有按钮

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 325,949. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.