TKinter—— 2 - 3 Basic Widget - Check buttons and radio button

6 篇文章 0 订阅
1 篇文章 0 订阅

-- Basic Widget  基础小组件

————— Check buttons and radio button ——————————

定义:

引导用户做出选择, 这些按钮可以帮助记录这些选项

check button 和 radio button 都包含一个value

 区别:

Check Button: 只能选择 是 或者

Radio Button

_______________________________________

使用:

Check button:

 

 

存储数据:

BooleanVar, DoubleVar, IntVar, StringVar

如果我们想把checkbutton的数据存下来

store = StringVar()
store.set('Yes!')

# return the value in the variable 
store.get()

# configure the check button
checkbutton.config(variable = store)

# onvalue is if the button is selected
checkbutton.config(onvalue = 'Yes plz', offvalue = 'No!'))

默认的存储是 1 是选中的, 0 是没有选中的

get() 返回button当前的状态

——————————————————

Radio Button:

Variable 代表这些button是一个系列

—————————————————————————

更改:

如果想更改设置:

label.config( arg = )

arg 可以是 text / image / font ... 

—————————————————————————

More:

checkbutton.config(textvariable = breakfast)

如果breakfast radio button 你选中的是什么 

checkbutton 的文字就会变成你选中的 text

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值