
- PyGTK Tutorial
- PyGTK - Home
- PyGTK - Introduction
- PyGTK - Environment
- PyGTK - Hello World
- PyGTK - Important Classes
- PyGTK - Window Class
- PyGTK - Button Class
- PyGTK - Label CLass
- PyGTK - Entry Class
- PyGTK - Signal Handling
- PyGTK - Event Handling
- PyGTK - Containers
- PyGTK - Box Class
- PyGTK - ButtonBox Class
- PyGTK - Alignment Class
- PyGTK - EventBox Class
- PyGTK - Layout Class
- PyGTK - ComboBox Class
- PyGTK - ToggleButton Class
- PyGTK - CheckButton Class
- PyGTK - RadioButton Class
- PyGTK - MenuBar, Menu & MenuItem
- PyGTK - Toolbar Class
- PyGTK - Adjustment Class
- PyGTK - Range Class
- PyGTK - Scale Class
- PyGTK - Scrollbar Class
- PyGTK - Dialog Class
- PyGTK - MessageDialog Class
- PyGTK - AboutDialog Class
- PyGTK - Font Selection Dialog
- PyGTK - Color Selection Dialog
- PyGTK - File Chooser Dialog
- PyGTK - Notebook Class
- PyGTK - Frame Class
- PyGTK - AspectFrame Class
- PyGTK - TreeView Class
- PyGTK - Paned Class
- PyGTK - Statusbar Class
- PyGTK - ProgressBar Class
- PyGTK - Viewport Class
- PyGTK - Scrolledwindow Class
- PyGTK - Arrow Class
- PyGTK - Image Class
- PyGTK - DrawingArea Class
- PyGTK - SpinButton Class
- PyGTK - Calendar Class
- PyGTK - Clipboard Class
- PyGTK - Ruler Class
- PyGTK - Timeout
- PyGTK - Drag and Drop
- PyGTK Useful Resources
- PyGTK - Quick Guide
- PyGTK - Useful Resources
- PyGTK - Discussion
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
PyGTK - Ruler Class
This is a base class for horizontal (gtk.Hruler) and vertical (gtk.Vruler) rulers that are useful to show mouse pointer's position in window. A small triangle in the ruler indicates the location of pointer.
Ruler objects are created with their respective constructors −
hrule = gtk.Hruler() vrule = gtk.Vruler()
The following gtk.Ruler class methods are available for both the derived classes −
Ruler.set_metric() − This sets the measurement unit. The predefined metric constants are: gtk.PIXELS (default), gtk.INCHES and gtk.CENTIMETERS
Ruler.set_range() − This sets the lower and upper bounds, position and maximum size of ruler.
In the example given below, the horizontal and vertical rulers are placed above and to the left of a gtk.TextView widget.
The measurement of horizontal ruler is in pixels. Its minimum and maximum values are 0 and 400 respectively. It is placed in the upper row of a gtk.VBox.
hrule = gtk.HRuler() hrule.set_metric(gtk.PIXELS) hrule.set_range(0, 4,0,0.5) vbox.pack_start(hrule)
The lower row of Vbox contains an HBox. A vertical ruler and a TextView widget, in which a multi-line text can be entered, is packed.
vrule=gtk.VRuler() vrule.set_metric(gtk.PIXELS) vrule.set_range(0, 4, 10, 0.5) hbox.pack_start(vrule)
Example
Observe the following code −
import gtk class PyApp(gtk.Window): def __init__(self): super(PyApp, self).__init__() self.set_title("Ruler demo") self.set_size_request(400,400) self.set_position(gtk.WIN_POS_CENTER) vbox = gtk.VBox() tv = gtk.TextView() tv.set_size_request(350,350) hrule = gtk.HRuler() hrule.set_metric(gtk.PIXELS) hrule.set_range(0, 4,0,0.5) vbox.pack_start(hrule) hbox = gtk.HBox() vrule = gtk.VRuler() vrule.set_metric(gtk.PIXELS) vrule.set_range(0, 4, 10, 0.5) hbox.pack_start(vrule) halign = gtk.Alignment(0.5, 0.5, 0, 0) halign.add(tv) hbox.pack_start(halign, False, True, 10) vbox.add(hbox) self.add(vbox) self.connect("destroy", gtk.main_quit) self.show_all() PyApp() gtk.main()
The output generated by the above program resembles an MS Word document −
