Python3 tkinter基础 Radiobutton 设置相同的value值,产生连锁效果

Posted xingchuxin

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python3 tkinter基础 Radiobutton 设置相同的value值,产生连锁效果相关的知识,希望对你有一定的参考价值。

?

  •                    python : 3.7.0
  •                           OS : Ubuntu 18.04.1 LTS
  •                          IDE : PyCharm 2018.2.4
  •                      conda : 4.5.11
  •            type setting : Markdown

?

code

"""
@Author : 行初心
@Date   : 18-10-1
@Blog   : www.cnblogs.com/xingchuxin
@GitHub : github.com/GratefulHeartCoder
"""
from tkinter import *


def main():
    root = Tk()

    v = IntVar()
    v.set(3)  # 如果1,那么儒家被默认选中
    # 如果2,那么道家被默认选中
    # 如果3,那么佛家被默认选中

    # 看到了吗?儒家和道家的value值是相同的,那么就会出现选其中任何一个,另外一个都会被选上
    rb1 = Radiobutton(root, text=‘儒家‘, variable=v, value=1)
    rb1.pack()

    rb2 = Radiobutton(root, text=‘道家‘, variable=v, value=1)
    rb2.pack()

    rb3 = Radiobutton(root, text=‘佛家‘, variable=v, value=3)
    rb3.pack()

    mainloop()


if __name__ == ‘__main__‘:
    main()

?

result

技术分享图片

技术分享图片

?

reference

  • [文档] https://docs.python.org/3/library/tkinter.html

?

resource

  • [文档] https://docs.python.org/3/
  • [规范] https://www.python.org/dev/peps/pep-0008/
  • [规范] https://zh-google-styleguide.readthedocs.io/en/latest/google-python-styleguide/python_language_rules/
  • [源码] https://www.python.org/downloads/source/
  • [ PEP ] https://www.python.org/dev/peps/
  • [平台] https://www.cnblogs.com/

?


Python具有开源、跨平台、解释型和交互式等特性,值得学习。
Python的设计哲学:优雅,明确,简单。提倡用一种方法,最好是只有一种方法来做一件事。
GUI可以选择PyQt5、PySide2、wxPython、PyGObject、wxWidgets等进行创作。
代码的书写要遵守规范,这样有助于沟通和理解。
每种语言都有独特的思想,初学者需要转变思维、踏实践行、坚持积累。






以上是关于Python3 tkinter基础 Radiobutton 设置相同的value值,产生连锁效果的主要内容,如果未能解决你的问题,请参考以下文章

Python3 tkinter基础 Tk quit 点击按钮退出窗体

Python3 tkinter基础 TK title 设置窗体的标题

Python3 tkinter基础 Tk quit 点击按钮退出窗体

Python3 Tkinter基础 Label 显示的文字换行

Python3 Tkinter基础 点击按钮退出窗体 root.quit

Python3 tkinter基础 Menubutton 点击按钮出现下拉菜单