码迷,mamicode.com
首页 > 其他好文 > 详细

tkinter 04 Radiobutton 选择按钮

时间:2018-04-16 13:06:38      阅读:132      评论:0      收藏:0      [点我收藏+]

标签:oop   str   tar   title   tle   href   imp   radio   结果   

  •  运行结果: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 选择按钮

标签:oop   str   tar   title   tle   href   imp   radio   结果   

原文地址:https://www.cnblogs.com/jkn1234/p/8855260.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!