zoukankan      html  css  js  c++  java
  • Tkinter之Radiobutton

    提供用户选项时会用到,一次只能选择其中一个,不能多选。
     
    示例:
    import Tkinter as tk 
    window = tk.Tk()
    window.title('My Window')
    window.geometry('500x300')  
     
     
    def print1():
        print ("你的选择是:"+v.get())   
     
    v = tk.StringVar()
    v.set('ss')    # 设置默认选中的按钮
     
    #当鼠标选中了某个选项,会把value的值放到变量v中,v再赋值给variable
    l1 = tk.Radiobutton(window, text='aaa', variable=v, value='aaa',command=print1)
    l1.pack(anchor='w')
    l2 = tk.Radiobutton(window, text='ss', variable=v, value='ss',command=print1)
    l2.pack(anchor='w')
    l3 = tk.Radiobutton(window, text='d', variable=v, value='d',command=print1)
    l3.pack(anchor='w')
     
        
    window.mainloop()
     
     
     
    比较实用的代码示例:
    import Tkinter as tk 
    window = tk.Tk()
    window.title('My Window')
    window.geometry('500x300')  
     
     
    def print1():
        print ("你的选择是:"+selectons[v.get()-1][0])
     
    selectons=[('python',1),('C++',2),('C',3)]
     
    v = tk.IntVar()
    v.set(3) 
     
    for i,j in selectons:
        l = tk.Radiobutton(window, text=i, variable=v, value=j,command=print1)
        l.pack(anchor='w')
        
        
    window.mainloop()
     
     
  • 相关阅读:
    CentOS7下安装Docker-Compose
    USDT(omniCore)测试环境搭建
    Centos中iptables和firewall防火墙开启、关闭、查看状态、基本设置等
    Docker导入导出镜像
    Linux下安装GO语言环境
    linux 查看磁盘空间大小
    rsync+sersync多线程实时同步
    rsync+inotify实时同步
    rsync高级同步
    NFS服务器
  • 原文地址:https://www.cnblogs.com/myshuzhimei/p/11764476.html
Copyright © 2011-2022 走看看