die - A Dmhwidget for depicting dice


dmhwidgets::die pathName ?options?


itk::Widget <- dmhwidgets::Die


activebackground activeforeground background font foreground

See the options manual entry for details on the standard options.


Name: flash  Class: Flash  Command-Line Switch: -flash  Default value: 1

The value is used as a boolean to determine if the die should flash when the show method is called to display a value.


The die command creates a widget that represents the face of a die, and a new Tcl command whose name is pathname. The command is then used to invoke various methods of the widget. The command has the general form:

pathName option ?arg arg ... arg?

The die is implemented as a button. The default button action is to invoke the roll method.

The button action can be changed by configuring the -command option of the bdie component. (For example, pathName component bdie configure -command newCommand.) The die depiction is based on displayed characters for the button text. A larger or smaller die can be obtained by configuring a larger or smaller fixed pitch font for the widget.


pathName roll
Show a random die face from 1 to 6. The return value is the chosen face value.
pathName show N
Display the die face for the value N. The value 0 displays a blank face.
pathName value
Return the numeric value corresponding to the displayed face.


package require Dmhwidgets

frame .dice 
pack .dice -side top -expand 1 -fill both

dmhwidgets::die .dice.d1
dmhwidgets::die .dice.d2
pack .dice.d1 .dice.d2 -side left -expand 0  -padx 10 -pady 10

button .diceb -text Roll -command dice_roll -width 8
pack .diceb -side top -padx 12m -pady 4m

proc dice_roll {} {
    .diceb configure -state disabled
    set sum 0
    foreach d [list .dice.d1 .dice.d2] {
        incr sum [$d roll]
    .diceb configure -state normal
    return $sum


Hume Integration Software,


dice, simulation, widget