你可以通过循环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)