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

tkinter 06 Checkbutton 勾选项

时间:2018-04-16 18:43:55      阅读:147      评论:0      收藏:0      [点我收藏+]

标签:gbk   com   style   ack   try   gif   variable   command   either   

  •  
    运行结果:https://s1.ax1x.com/2018/04/16/CewO0O.gif
  • # coding=gbk
    # 运行结果:https://s1.ax1x.com/2018/04/16/CewO0O.gif
    import tkinter as tk
    
    window = tk.Tk()
    window.title(my window)
    window.geometry(200x200)
    
    l = tk.Label(window, bg=yellow, width=20, text=empty)
    l.pack()
    
    def print_selection():
        if (var1.get() == 1) & (var2.get() == 0):
            l.config(text=I love only Python )
        elif (var1.get() == 0) & (var2.get() == 1):
            l.config(text=I love only C++)
        elif (var1.get() == 0) & (var2.get() == 0):
            l.config(text=I do not love either)
        else:
            l.config(text=I love both)
    
    var1 = tk.IntVar()
    var2 = tk.IntVar()
    c1 = tk.Checkbutton(window, text=Python,
                        variable=var1, onvalue=1, offvalue=0,
                        command=print_selection)
    c2 = tk.Checkbutton(window, text=C++,
                        variable=var2, onvalue=1, offvalue=0,
                        command=print_selection)
    c1.pack()
    c2.pack()
    
    
    window.mainloop()

     

tkinter 06 Checkbutton 勾选项

标签:gbk   com   style   ack   try   gif   variable   command   either   

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

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