June 2002
Beginner to intermediate
640 pages
14h 24m
English
With JFC, to make the buttons look and behave like radio buttons, you have to use JRadioButton. Let's continue our one-topping example, using JRadioButton in a button group to allow only one checkbox to be selected.
for a_checkbox in checkboxes:
panel.remove(a_checkbox)
group = ButtonGroup()
from javax.swing import JRadioButton
rb = JRadioButton #rb is JRadioButton class.
#Remember classes are first class objects in Python.
pepperoni = rb("pepperoni")
radiobuttons=(pepperoni,rb("peppers"),rb("olives"),rb("anchovies"),
rb("onions"),rb("sausage"))
for a_radiobutton in radiobuttons:
group.add(a_radiobutton)
panel.add(a_radiobutton)
pepperoni.selected = 1
frame.pack()
Try these exercises:
Change the event handler to work with JRadioButton ...
Read now
Unlock full access