python循环点击按钮,如何使用循环在Python中创建单选按钮

你可以通过循环RADIOLABELS这样做。注意:还建议将按钮保存到列表中,以免丢失。

self.RADIOLABELS = ( # Text, Font, Variable, Value, Row, Column

('English', self.FONTS[3], self.unitType, 1, 3, 1),

('metric', self.FONTS[3], self.unitType, 2, 4, 1),

('select preset', self.FONTS[3], self.matPropSel, 1, 6, 1),

('manual entry', self.FONTS[3], self.matPropSel, 2, 7, 1),

('select preset', self.FONTS[3], self.secProfSel, 1, 10, 1),

('manual entry', self.FONTS[3], self.secProfSel, 2, 11, 1),

('one end', self.FONTS[3], self.endSupSel, 1, 15, 1),

('both ends', self.FONTS[3], self.endSupSel, 2, 16, 1),

('point', self.FONTS[3], self.loadTypeSel, 1, 18, 1),

('uniform distribution', self.FONTS[3], self.loadTypeSel, 2, 19, 1),

('uniform variation', self.FONTS[3], self.loadTypeSel, 3, 20, 1)

)

radiobuttons = []

for _Text, _Font, _Variable, _Value, _Row, _Column in self.RADIOLABELS: # it will unpack the values during each iteration

_Radio = tk.Radiobutton(root, text = _Text, font = _Font, variable = _Variable, value = _Value)

# ^ root should be the frame/Tk you're trying to place it on, it will be self if this is a direct subclass of a Frame or Tk

# ^ or Radiobutton(.....) if you did from tkinter import *

_Radio.grid(row = _Row, column = _Column)

radiobuttons.append(_Radio)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值