AGW Logo

agw_title rulerctrl

RulerCtrl implements a ruler window that can be placed on top, bottom, left or right to any wxPython widget.

description Description

RulerCtrl implements a ruler window that can be placed on top, bottom, left or right to any wxPython widget. It is somewhat similar to the rulers you can find in text editors software, though not so powerful.

RulerCtrl has the following characteristics:

  • Can be horizontal or vertical;
  • 4 built-in formats: integer, real, time and linearDB formats;
  • Units (as cm, dB, inches) can be displayed together with the label values;
  • Possibility to add a number of “paragraph indicators”, small arrows that point at the current indicator position;
  • Customizable background colour, tick colour, label colour;
  • Possibility to flip the ruler (i.e. changing the tick alignment);
  • Changing individually the indicator colour (requires PIL at the moment);
  • Different window borders are supported (wx.STATIC_BORDER, wx.SUNKEN_BORDER, wx.DOUBLE_BORDER, wx.NO_BORDER, wx.RAISED_BORDER, wx.SIMPLE_BORDER);
  • Logarithmic scale available;
  • Possibility to draw a thin line over a selected window when moving an indicator, which emulates the text editors software.

And a lot more. See the demo for a review of the functionalities.

usage Usage

Usage example:

import wx
import wx.lib.agw.rulerctrl as RC

class MyFrame(wx.Frame):

    def __init__(self, parent):

        wx.Frame.__init__(self, parent, -1, "RulerCtrl Demo")

        panel = wx.Panel(self)

        text = wx.TextCtrl(panel, -1, "Hello World! wxPython rules", style=wx.TE_MULTILINE)

        ruler1 = RC.RulerCtrl(panel, -1, orient=wx.HORIZONTAL, style=wx.SUNKEN_BORDER)
        ruler2 = RC.RulerCtrl(panel, -1, orient=wx.VERTICAL, style=wx.SUNKEN_BORDER)

        mainsizer = wx.BoxSizer(wx.HORIZONTAL)
        leftsizer = wx.BoxSizer(wx.VERTICAL)
        bottomleftsizer = wx.BoxSizer(wx.HORIZONTAL)
        topsizer = wx.BoxSizer(wx.HORIZONTAL)

        leftsizer.Add((20, 20), 0, wx.ADJUST_MINSIZE, 0)
        topsizer.Add((39, 0), 0, wx.ADJUST_MINSIZE, 0)
        topsizer.Add(ruler1, 1, wx.EXPAND, 0)
        leftsizer.Add(topsizer, 0, wx.EXPAND, 0)

        bottomleftsizer.Add((10, 0))
        bottomleftsizer.Add(ruler2, 0, wx.EXPAND, 0)
        bottomleftsizer.Add(text, 1, wx.EXPAND, 0)
        leftsizer.Add(bottomleftsizer, 1, wx.EXPAND, 0)
        mainsizer.Add(leftsizer, 3, wx.EXPAND, 0)


# our normal wxApp-derived class, as usual

app = wx.PySimpleApp()

frame = MyFrame(None)


This code snippet can be downloaded, see this example script.


Some of the AGW snippets of code in the documentation use images and external files (to create bitmaps or access external data). As these files are not provided in these snippets, you should make the approriate modifications to the code to actually run it.

events Events

RulerCtrl implements the following events related to indicators:

  • EVT_INDICATOR_CHANGING: the user is about to change the position of one indicator;
  • EVT_INDICATOR_CHANGED: the user has changed the position of one indicator.

platforms Supported Platforms

RulerCtrl has been tested on the following platforms:
  • Windows (Windows XP);
  • Linux Ubuntu (Dapper 6.06)

styles Window Styles

No particular window styles are available for this class.

events Events Processing

This class processes the following events:

Events processing for rulerctrl
Event Name Description
EVT_INDICATOR_CHANGED The user has changed the indicator value.
EVT_INDICATOR_CHANGING The user is about to change the indicator value.

license License And Version

RulerCtrl is distributed under the wxPython license.

Latest Revision: Andrea Gavana @ 17 Aug 2011, 15.00 GMT

Version 0.3

Module author: Andrea Gavana <>

hierarchy Inheritance Diagram

Inheritance diagram for module: rulerctrl

Inheritance diagram of rulerctrl.Indicator, rulerctrl.Label, rulerctrl.RulerCtrl, rulerctrl.RulerCtrlEvent

svn_main SVN Revisions

A graphical representation of the SVN commits in the last year.

Click on any date in the picture to jump to that particular revision page, containing information about committers, log messages and SVN diffs.


Revision Graph For rulerctrl

2to3 Python 3 Issues (via 2to3)

No issues have been detected by