class Gui

Public Class Methods

button(btntxt, m, x,y) click to toggle source

__ method to draw a button with text (btntxt), triggering method (m) and coordinates x,y

# File lib/gui.rb, line 53
def self.button(btntxt, m, x,y)
   TkButton.new(root){
   text  "#{btntxt}"
   command(m)
   grid('row' => x, 'column' => y, 'padx' => 10, 'pady' => 15)}
end
entry(var, x, y) click to toggle source

__ method to draw an entry field sending value to variable (var)[ use $var1 to $var3]

# File lib/gui.rb, line 62
def self.entry(var, x, y)
  TkEntry.new(root){
    textvariable var
   grid('row' => x, 'column' => y, 'padx' => 10, 'pady' => 15)}
end
header(hdtxt, x, y) click to toggle source

_ HEADER _

# File lib/gui.rb, line 38
def self.header(hdtxt, x, y)
 TkLabel.new(root){
    text "#{hdtxt}"
    background "green"
    borderwidth 4
    font TkFont.new('Proxima 16 bold')
    foreground  "black"
    'padx' '10'
    'pady' '15'
    justify "center"
    relief 'raised'
    grid('rowspan' => x, 'columnspan' => y, 'padx' => 10, 'pady' => 15)}
end
help_win() click to toggle source

A class which uses Tcl/Tk to build a GUI for user interaction _ we start by building a Toplevel Help window which is used by a menu as a Help guide

# File lib/gui.rb, line 8
def self.help_win
$win = TkToplevel.new{title "Help Window"}
$scrollbar = TkScrollbar.new($win){command proc{|*args| $textwin.yview(*args)}
}.pack('side' => 'right', 'fill' => 'y')
$textwin =TkText.new($win){
  borderwidth 1
  wrap 'word'
  font TkFont.new('times 14 bold')
  background  "yellow"
  pack('side' => 'left')
}
$guide = Guide.view
$textwin.insert(1.0, "#{$guide}")
$textwin.yscrollcommand(proc{|first, last| $scrollbar.set(first, last)})
end
label(lbltxt, x,y) click to toggle source

_ method to draw a label with text (lbltxt) and coordinates x,y in a grid

# File lib/gui.rb, line 32
def self.label(lbltxt, x,y)
  TkLabel.new(root){
    text "#{lbltxt}"
    grid('row' => x, 'column' => y, 'padx' => 10, 'pady' => 15)}
end
menu() click to toggle source

__ MENU _

root() click to toggle source

_ method to build the root main window

# File lib/gui.rb, line 25
def self.root
TkRoot.new{
title "#$title"
}
end
show() click to toggle source

__ The final and essential step, to run the mainloop for GUI to display

# File lib/gui.rb, line 143
def self.show
Tk.mainloop
end
textfield(w, h, x, y) click to toggle source

_ method to draw a textfield with specific width (w), height (h), background color (bg) and foreground color (fg), and coordinates x, y, with vertical scrollbar

# File lib/gui.rb, line 70
def self.textfield(w, h, x, y)
  $textfield = TkText.new(root){
    width w
    height h
    background "black"
    foreground  "white"
    font TkFont.new('times 14 bold')
    grid('rowspan' => x, 'columnspan' => y, 'padx' => 10, 'pady' => 15)
        }
end

Public Instance Methods

scroll() click to toggle source

__

The Scrollbar to use with textfield widget

# File lib/gui.rb, line 82
def scroll
$scroll = TkScrollbar.new{command proc{|*args|
    $textfield.yview(*args)
        $textfield.yscrollcommand(proc {|first, last| $scroll.set(first, last)})
    pack('side' => 'right', 'fill' => 'y')}
        }
end