Module: Tk

Defined in:
lib/tk_paradise/base/base.rb,
lib/tk_paradise/tk_paradise.rb,
lib/tk_paradise/tk_classes/root.rb,
lib/tk_paradise/version/version.rb,
lib/tk_paradise/tk_classes/label.rb

Overview

#

require ‘tk_paradise/tk_classes/label.rb’

#

Defined Under Namespace

Classes: Base, Root, TkLabel

Constant Summary collapse

Grid =
#

Provide some “aliases”.

#
TkGrid
Font =
TkFont
VERSION =
#

VERSION

#
'0.0.14'
LAST_UPDATE =
#

LAST_UPDATE

#
'30.12.2023'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.root(hash = {}, &block) ⇒ Object

#

Tk.root

#


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/tk_paradise/tk_paradise.rb', line 43

def self.root(hash = {}, &block)
  root = TkRoot.new { hash }
  if block_given?
    yielded = yield
    if yielded.is_a? Hash
      # =================================================================== #
      # === :geometry
      # =================================================================== #
      if yielded.has_key? :geometry
        root.geometry(yielded[:geometry])
      end
      # =================================================================== #
      # === :title
      # =================================================================== #
      if yielded.has_key? :title
        root.title = yielded[:title]
      end
    end
  end
  return root
end

.runObject

#

Tk.run

#


36
37
38
# File 'lib/tk_paradise/tk_paradise.rb', line 36

def self.run
  ::Tk.mainloop
end

Instance Method Details

#e(i = '') ⇒ Object

#

e

#


29
30
31
# File 'lib/tk_paradise/tk_paradise.rb', line 29

def e(i = '')
  puts i
end

#tk_image(path_to_the_image, extra_arguments = { height: 50 }) ⇒ Object Also known as: image

#

tk_image

Usage examples:

- create an empty image of 300x200 pixels:

    image = TkPhotoImage.new(height: 200, width: 300)

- create an image from a file:

    image = TkPhotoImage.new(file: 'my_image.gif')
#


118
119
120
121
122
123
124
125
126
# File 'lib/tk_paradise/tk_paradise.rb', line 118

def tk_image(
    path_to_the_image,
    extra_arguments = { height: 50 }
  )
  hash = {}
  hash['file'] = path_to_the_image
  hash.merge(extra_arguments)
  return ::TkPhotoImage.new(hash)
end

#tk_label(text_to_use = '', root_widget = nil, font = nil) ⇒ Object Also known as: label

#

tk_label

The second argument should be the root-widget.

Usage example:

tk_label('Message in the Bottom', root) { :on_bottom }
#


75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/tk_paradise/tk_paradise.rb', line 75

def tk_label(
    text_to_use = '',
    root_widget = nil,
    font        = nil # fontStyle = tkFont.Font(family="Lucida Grande", size=20)
  )
  pack_onto_this_side = 'bottom'
  # ======================================================================= #
  # === Handle blocks next
  # ======================================================================= #
  if block_given?
    yielded = yield
    case yielded # case tag
    # ===================================================================== #
    # === :on_bottom
    # ===================================================================== #
    when :on_bottom
      pack_onto_this_side = 'bottom'
    # ===================================================================== #
    # === :on_right
    # ===================================================================== #
    when :on_right
      pack_onto_this_side = 'right'
    end
  end
  ::TkMessage.new(root_widget) {
    text(text_to_use)
  }.pack('side' => pack_onto_this_side)
end