Ruby/TK - ProgressBar Widget



A ProgressBar provides a widget, which will show a graphical representation of a value, given maximum and minimum reference values.


Here is a simple syntax to create this widget − {
   .....Standard Options....
   .....Widget-specific Options....

Standard Options

  • borderwidth
  • highlightthickness
  • padx
  • pady
  • relief
  • troughcolor

These options have been described in the previous chapter.

Widget Specific Options

Sr.No. Options & Description

anchor => String

This can be used to position the start point of the bar. Default is 'w' (horizontal bar starting from the left). A vertical bar can be configured by using either 's' or 'n'.


blocks => Integer

This controls the number of blocks to be used to construct the progress bar. The default is to break the bar into 10 blocks.


colors => String

Controls the colors to be used for different positions of the progress bar.


from => Integer

This sets the lower limit of the progress bar. If the bar is set to a value below the lower limit no bar will be displayed. Defaults to 0.


gap => Integer

This is the spacing (in pixels) between each block. Defaults to 1. Use 0 to get a continuous bar.


length => Integer

Specifies the desired long dimension of the ProgressBar in screen units.


resolution => Integer

A real value specifying the resolution for the scale. If this value is greater than zero, then the scale's value will always be rounded to an even multiple of this value, as will tick marks and the endpoints of the scale. Defaults to 1.


to => Integer

This sets the upper limit of the progress bar. If a value is specified (for example, using the value method) that lies above this value the full progress bar will be displayed. Defaults to 100.


variable => Variable

Specifies the reference to a scalar variable to link to the ProgressBar. Whenever the value of the variable changes, the ProgressBar will update to reflect this value.


value => Integer

The can be used to set the current position of the progress bar when used in conjunction with the standard configure. It is usually recommended to use the value method instead.


width => Integer

Specifies the desired narrow dimension of the ProgressBar in screen units

Manipulating Progress Bar

You can use value(?value?) method along with ProgressBar instance to get current value of the ProgressBar. If value is given, the value of the ProgressBar is set.


require 'tk'
require 'tkextlib/bwidget'

root =
root.title = "Window"

progressBar =

variable =
progressBar.variable = variable

variable.value = 33

progressBar.maximum = 100'height' => 25, 'width'  => 100, 'x'      => 10, 'y'      => 10)


This will produce the following result −

Ruby/Tk Progress Bar