tkinter 04 Radiobutton 选择按钮

Posted jkn1234

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了tkinter 04 Radiobutton 选择按钮相关的知识,希望对你有一定的参考价值。

  •  运行结果:http://ww1.sinaimg.cn/large/de060ec1ly1fqedlvhm4ag20fe09eaaf.gif
  • # coding=gbk
    # 注意:选中按钮时执行下面的命令,config意为配置
    #       lable.config(text = "you have selected " + var.get())
    # 运行结果:http://ww1.sinaimg.cn/large/de060ec1ly1fqedlvhm4ag20fe09eaaf.gif
    import tkinter
    window = tkinter.Tk()
    window.title("jkn1234")
    window.geometry("500x500")
    
    var = tkinter.StringVar()
    lable = tkinter.Label(
        window,
        bg = yellow,
        height = 6,
        text = empty
    )
    def print_selection():
        lable.config(text = "you have selected " + var.get())
    lable.pack()
    
    radiobutton1 = tkinter.Radiobutton(
        window,
        variable = var, value = A,#点击按钮时将按钮var的值设置为‘A’
        text = "option A",
        command = print_selection
    )
    radiobutton1.pack()
    radiobutton2 = tkinter.Radiobutton(
        window,
        variable = var, value = B,#点击按钮时将按钮var的值设置为‘B’
        text = "option B",
        command = print_selection
    )
    radiobutton2.pack()
    window.mainloop()

     

以上是关于tkinter 04 Radiobutton 选择按钮的主要内容,如果未能解决你的问题,请参考以下文章

tkinter 笔记: radiobutton 选择按钮(莫烦python笔记)

Python3 tkinter基础 Radiobutton variable 默认选中的按钮

Python3 tkinter基础 Radiobutton 创建三个单选钮

Python3 tkinter基础 Radiobutton indicatoron 改变按钮的外观 圆形/方形

Python3 tkinter基础 Radiobutton indicatoron 长条形 pack 充满一行

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