Tkinter——⑥checkbutton(复选按钮)

Tkinter——checkbutton(复选按钮)

python入门常用操作:https://blog.csdn.net/qq_33302004/article/details/112859327

 

import tkinter as tk

window = tk.Tk()
window.title('checkbutton')
window.geometry('300x300')

label = tk.Label(window, bg='yellow', width=25, text = '')
label.pack()

checkbutton_1_variable = tk.BooleanVar()
checkbutton_2_variable = tk.BooleanVar()
def print_selected():
    if(checkbutton_1_variable.get() and checkbutton_2_variable.get()):
        label.config(text='I love both')
    elif( checkbutton_1_variable.get() and (not checkbutton_2_variable.get())):
        label.config(text='I do not love python')
    elif( (not checkbutton_1_variable.get()) and checkbutton_2_variable.get()):
        label.config(text='I do not love c++')
    else:
        label.config(text='I do not love either')
    return

# onvalue=1, offvalue=0
# 选中的时候值为1,不选中的时候值为0
checkbutton_1 = tk.Checkbutton(window, text='python', variable=checkbutton_1_variable, onvalue=True, offvalue=False, command=print_selected)
checkbutton_2 = tk.Checkbutton(window, text='c++', variable=checkbutton_2_variable, onvalue=True, offvalue=False, command=print_selected)

checkbutton_1.pack()
checkbutton_2.pack()

window.mainloop()

效果:

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值