{"id":24810812,"url":"https://github.com/davidho123/defgui","last_synced_at":"2026-02-13T15:37:38.834Z","repository":{"id":245236420,"uuid":"817901188","full_name":"davidho123/defgui","owner":"davidho123","description":"Decorator for Fast Generation of Function Input Output Components with Tkinter or Streamlit。装饰器，使用Tkinter或Streamlit快速生成函数输入输出组件。","archived":false,"fork":false,"pushed_at":"2025-01-07T06:39:15.000Z","size":120,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-17T15:54:55.565Z","etag":null,"topics":["defgui","function","gui","streamlit","tkinter"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/davidho123.png","metadata":{"files":{"readme":"README-zh.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-06-20T17:15:21.000Z","updated_at":"2025-01-07T06:39:19.000Z","dependencies_parsed_at":"2024-11-15T09:38:07.396Z","dependency_job_id":"2bc77f31-afb5-4000-8126-bc8c0708f9ae","html_url":"https://github.com/davidho123/defgui","commit_stats":null,"previous_names":["davidho123/defgui"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/davidho123/defgui","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidho123%2Fdefgui","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidho123%2Fdefgui/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidho123%2Fdefgui/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidho123%2Fdefgui/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/davidho123","download_url":"https://codeload.github.com/davidho123/defgui/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidho123%2Fdefgui/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271983849,"owners_count":24853810,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-24T02:00:11.135Z","response_time":111,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["defgui","function","gui","streamlit","tkinter"],"created_at":"2025-01-30T12:18:06.090Z","updated_at":"2026-02-13T15:37:38.809Z","avatar_url":"https://github.com/davidho123.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"![logo](logo.png)\n\n本模块是一个函数装饰器，根据函数的参数和返回值，自动生成相应的gui组件\n\n## 目录\n* [概述](README-zh.md#一、概述)\n* [功能](README-zh.md#二、功能)\n* [使用方法](README-zh.md#三、使用方法)\n* [版本说明](README-zh.md#四、版本说明)\n\n## 一、概述\n本模块灵感来源于[magicgui](https://github.com/pyapp-kit/magicgui)，感谢作者\n\n本模块设置两个分支，一个基于tkinter，一个基于streamlit\n\n与magicgui的主要区别：\n\n1、magicgui使用的工具是pyqt和pyside，本模块使用的是tkinter和streamlit\n2、本模块只提供装饰器生成组件，不提供单独的gui组件\n3、本模块可以返回输入组件的输入值，方便单独使用。\n\n## 二、功能\n基本功能：使用装饰器，根据函数的参数和返回值，自动生成对应的gui组件。\n\ntkinter分支\n\u003e \t- 本分支主要基于tkinter，以及python标准库中的typing、ctypes。不需要安装pyside等第三方依赖。\n\u003e \t- 本分支本着简易使用的原则，只有一个装饰器函数，没有其他参数设置。\n\u003e \t- 本分支生成的输出组件，与返回值结果数量一致。\n\u003e \t- 进行了DPI的自动适配，界面不会显示模糊\n\u003e \t- 目前支持的参数类型：int、float、str、List[str]\n\nstreamlit分支\n\u003e \t- 本分支主要基于streamlit\n\u003e \t- 本分支可以设置输入组件水平放置，或者垂直放置。\n\u003e \t- 水平放置时，可以设置每个组件列宽比例。\n\u003e \t- 设置是否显示执行按钮，是否进行函数运算。\n\u003e \t- 返回每个组件的输入值，和函数运行结果值，用于后续单独使用。\n\n## 三、使用方法\n\n常规安装，包含tkinter和streamlit模块\n```python\npip install defgui\npip install streamlit\n```\n\n\u003e如果不需要使用streamlit，则安装 v 0.1版本\n\u003e```python\n\u003epip install defgui==0.1\n\u003e```\n\n\n直接在函数上加上装饰器就可以使用\n\n### 注意：定义函数时，参数需要带类型标识，否则报错\n\n### 1、tkinter分支使用\n\n- 本分支类型标识目前支持：int、float、str、List[str]\n- 点击自动生成的run按钮，显示输出结果\n\n```python\nfrom defgui import defgui_tkinter\nfrom typing import List\n\n# 定义函数\n@defgui_tkinter\ndef example_function(a: int, b: float,c: str,d: List[str])-\u003e tuple:\n\t\"\"\"Example function that returns a tuple of four values.\"\"\"\n\treturn a + 1, b + 1,\"str：%s\"%(c),d\n\n# 运行函数\nexample_function()\n```\n运行结果\n\n![png](result.png)\n\n### 2、streamlit分支使用\n\n- 本分支类型标识目前支持：int、float、str、bool、list、datetime.date\n- list参数，没有赋值时，生成组件因为没有可选项，会显示灰色不可用。建议list参数赋值运行。\n- datetime.date参数，没有赋值时，生成的日期组件，默认使用当天日期\n- 定义函数时，参数可以是位置参数，也可以是关键字参数，但必须有类型标识，否则报错\n- 本分支装饰器，有3个默认参数：horizontal=True, col_size=None, execute=True\n- **horizontal=True：**输入组件默认以水平排列\n- **col_size=None：**列尺寸默认不设置，按输入组件数量，平均划分列宽\n- **execute=True：**默认显示执行按钮，并进行函数运算。False则不显示。\n- 被装饰函数执行时，默认返回输入组件值和结果值。输入组件值类型是列表，列表项顺序与函数的参数顺序一致。\n- 被装饰函数可以赋值执行，也可以不赋值运行\n\n0.2.1版本更新说明：\n- 参数输入值返回，由列表改为字典形式，键名为参数名，键值为输入值。\n\n```python\nfrom defgui import defgui_streamlit\nimport streamlit as st\nimport datetime\n\nst.set_page_config(layout=\"wide\")\nst.title(\"Streamlit Decorator App\")\n\n@defgui_streamlit(horizontal=True, col_size=[1, 1, 1, 2, 2],execute=True)\ndef greet(date: datetime.date, name: str, age: int=20 , food: list=[]) -\u003e str:\n\t\n\t# 函数只作为输入组件使用时，直接return即可 \n\treturn  f\"{date}, Hello, {name}! You are {age} years old, you like {food}\"\n\ngreet_params, results = greet(name=\"david\",food=[\"apple\", \"banana\"])\n\nst.write(greet_params[\"name\"])  #使用参数名称获取输入值\n\n```\n\n下面是0.2版本的说明\n\n（1）参数赋值运行、组件水平排列、显示执行按钮\n```python\nfrom defgui import defgui_streamlit\nimport streamlit as st\nimport datetime\n\nst.set_page_config(layout=\"wide\")\nst.title(\"Streamlit Decorator App\")\n\n@defgui_streamlit(horizontal=True, col_size=[1, 1, 1, 2, 2], execute=True)\ndef greet(date: datetime.date, name: str, age: int=20 , food: list=[]) -\u003e str:\n\treturn f\"{date}, Hello, {name}! You are {age} years old, you like {food}\"\n\ninput_values, results = greet(name=\"david\",food=[\"apple\", \"banana\"])\n\nst.write(input_values[1])\n\n```\n![png](defgui_streamlit_h.png)\n\n（2）参数不赋值，组件竖向排列，不显示执行按钮\n```python\nfrom defgui import defgui_streamlit\nimport streamlit as st\nimport datetime\nst.set_page_config(layout=\"wide\")\nst.title(\"Streamlit Decorator App\")\n\n@defgui_streamlit(horizontal=False, col_size=None, execute=False)\ndef greet(date: datetime.date, name: str, age: int , food: list) -\u003e str:\n\treturn f\"{date}, Hello, {name}! You are {age} years old, you like {food}\"\n\ncols = st.columns(3)\nwith cols[0]:\n\tgreet()\n\n```\n![png](defgui_streamlit_c.png)\n\n## 四、版本说明\nv 0.2.1\n函数参数的输入值返回，由列表改为字典形式\n\nv 0.2\n增加基于streamlit的装饰器\n\nv 0.1\n基于tkinter的装饰器\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidho123%2Fdefgui","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdavidho123%2Fdefgui","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidho123%2Fdefgui/lists"}