next up previous contents index
Next: Menüs Up: Widgets Previous: Checkbuttons

Radiobuttons

  Radiobuttons erzeugen Optionsfelder zur Auswahl von nur einer Option, was bedeuted, daß sich die Optionen des Radiobuttons gegenseitig ausschließen. Die Funktion des Widgets ist an Stationstasten eines Autoradios angelehnt, mit denen immer nur ein Sender ausgewählt werden kann. Graphisch zeigt sich ein Radiobutton als eine Raute. Der gegenseitige Ausschluß wird über eine gemeinsame globale Variable realisiert, die mit der Ressource -variable spezifiziert wird. Jeder Radiobutton, in einer so festgelegten Gruppe, setzt die Variable auf einen eindeutigen Wert, wenn er gedrückt wird. Dieser spezifische Wert wird über die Ressource -value festgelegt. Auch hier kann mit der Ressource -command eine Prouzedur an den Radiobutton gebunden werden, die bei jeder Aktivierung ausgeführt wird.

 
Figure: Check-, und Radiobuttons

   #!/usr/bin/wish -f
   #-----------------------------------------------------------#
   #
   # Programmname : crbuttons.tk
   # TK-Version 4.0 TCL-Version 7.4
   # Erstellungsatum: Mon Sep 9 12:09:37 GMT 1996
   #
   #-----------------------------------------------------------#


   set FONT times
   set WEIGHT 0
   set SLANT 0


   frame .fc -bd 5m
   frame .fr -bd 5m

   checkbutton .fc.fett -anchor w -text "fett" -variable WEIGHT       \
         -command setFont
   checkbutton .fc.kursiv -anchor w -text "kursiv" -variable SLANT    \
         -command setFont

   radiobutton .fr.times -anchor w -text "times" -variable FONT       \
   	   -command setFont -value times
   radiobutton .fr.courier -anchor w -text "courier" -variable FONT   \
   	   -command setFont -value courier
   radiobutton .fr.helvetica -anchor w -text "charter" -variable FONT \
   	   -command setFont -value charter
   
   button .b -text "Quit" -command exit \
         -font "-*-times-medium-r-*--16-*-*-*-*-*-*-*"

   pack .b -side bottom -fill x
   pack .fc .fr -side left -fill both -expand 1
   pack .fc.fett .fc.kursiv -fill x
   pack .fr.times .fr.courier .fr.helvetica -fill x


   #==========================================================#
   # Prozedur zum aendern des Fonts
   #----------------------------------------------------------#

   proc setFont {} {
      global FONT
      global WEIGHT
      global SLANT

      if {$WEIGHT == 1} {
         set weight "bold" 
      } else {
         set weight "medium"
      }
	
      if {$SLANT  == 1} {
         set slant "i" 
      } else {
         set slant "r"
      }

      .b configure -font [list -*-$FONT-$weight-$slant-*--16-*-*-*-*-*-*-*]
   }



Sascha Scherer
Fri Dec 6 09:58:01 MET 1996