V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
angel725
V2EX  ›  Python

Python 的 tkinter 先创建 radiobutton 后,怎么给属性 text 赋值

  •  
  •   angel725 · 2019-06-03 20:07:40 +08:00 · 1575 次点击
    这是一个创建于 1791 天前的主题,其中的信息可能已经有所发展或是发生改变。

    for n in range(4): tk.Radiobutton(tab_one, text='加载中', variable=Var, value=n).grid(row=n, column=0, sticky=tk.W)

    我用 for 创建了 4 个 radiobutton,

    然后会动态读入 4 个名字 存到 name 列表里。

    因为 tkinter 创建窗口是时 name 列表里还没来得及读入数据。

    所以 radiobutton 的 text 默认是:加载中

    但问题是:name 存入数据后,我怎么把它传给 4 个 radiobutton 的 text 属性。

    让它们显示出来??

    2 条回复    2019-06-04 16:07:32 +08:00
    chen36330105
        1
    chen36330105  
       2019-06-04 11:29:57 +08:00
    str = [tk.StringVar() for x in range(4)]

    for n in range(4):
    tk.Radiobutton(tab_one, text='加载中', variable=Var, value=n).grid(row=n, column=0, sticky=tk.W)
    angel725
        2
    angel725  
    OP
       2019-06-04 16:07:32 +08:00
    先创建 gui 后,修改 radiobutton 的 text
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1278 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 17:49 · PVG 01:49 · LAX 10:49 · JFK 13:49
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.