首页 > 其他 > 详细

tkinter 04 Radiobutton 选择按钮

时间:2018-04-16 12:29:32      阅读:202      评论:0      收藏:0      [点我收藏+]
  •  运行结果: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 选择按钮

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!