Create  Edit  FrontPage  Index  Search  Changes  History  RSS  Login

tut-gtk2-numtxt-hvscales

Horizontal And Vertical Scales

Horizontal Scale


numtxt-hvscales.png

If you've studied and tried examples in the previous session discussing Spin Buttons you should have no trouble understanding examples here.

#!/usr/bin/env ruby
require 'gtk2'

window = Gtk::Window.new(Gtk::Window::TOPLEVEL)
window.set_title  "scales"
window.border_width = 10
window.signal_connect('delete_event') { Gtk.main_quit }
window.set_size_request(250, -1)
                           # min, max,  step
integer = Gtk::HScale.new(0.0, 10.0, 1.0)
float   = Gtk::HScale.new(0.0, 1.0,  0.1)
integer.value_pos = Gtk::POS_RIGHT
float.value_pos = Gtk::POS_LEFT

vbox = Gtk::VBox.new(true, 5)
vbox.pack_start(integer, false, true, 0)
vbox.pack_start(float,   false, true, 0)

window.add(vbox)
window.show_all
Gtk.main

Vertical Scale


numtxt-hvscales-v.png

The following example is almost identical to what you've seen above, however it uses adjustments. To learn more about Gtk::Adjustment checkout previous session discussing Spin Buttons.

require 'gtk2'

window = Gtk::Window.new(Gtk::Window::TOPLEVEL)
window.set_title  "Vertical Scales"
window.border_width = 10
window.signal_connect('delete_event') { Gtk.main_quit }
window.set_size_request(-1, 150)

# create two adjustments
                            # value min, max, step  pg-incr pg-size
int_adj   = Gtk::Adjustment.new(5.0, 0.0, 10.0, 1.0,  2.0,  0.0)
float_adj = Gtk::Adjustment.new(0.5, 0.0, 1.0,  0.1, 0.5,   0.0)

scale_int   = Gtk::VScale.new(int_adj)
scale_float = Gtk::VScale.new(float_adj)
scale_int.value_pos   = Gtk::POS_RIGHT
scale_float.value_pos = Gtk::POS_LEFT

hbox = Gtk::HBox.new(true, 5)
hbox.pack_start_defaults(scale_int)
hbox.pack_start_defaults(scale_float)

window.add(hbox)
window.show_all
Gtk.main
GtkPositionType
Describes which edge of a widget a certain feature is positioned at, e.g. the tabs of a Gtk::Notebook, the handle of a Gtk::HandleBox or the label of a Gtk::Scale.
  • POS_LEFT - The feature is at the left edge.
  • POS_RIGHT - The feature is at the right edge.
  • POS_TOP - The feature is at the top edge.
  • POS_BOTTOM - The feature is at the bottom edge.
Last modified:2009/01/18 13:41:27
Keyword(s):
References:[tut-gtk2-btt] [tut-gtk2-numtxt] [tut-gtk]