tk_paradise 0.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of tk_paradise might be problematic. Click here for more details.

Files changed (28) hide show
  1. checksums.yaml +7 -0
  2. data/doc/HINTS.md +318 -0
  3. data/lib/tk_paradise/base/base.rb +63 -0
  4. data/lib/tk_paradise/examples/001_dialog_box_example.rb +21 -0
  5. data/lib/tk_paradise/examples/002_draw_tiny_box.rb +22 -0
  6. data/lib/tk_paradise/examples/003_fun_with_cursors.rb +82 -0
  7. data/lib/tk_paradise/examples/004_hello_world_example.rb +22 -0
  8. data/lib/tk_paradise/examples/005_key_press_event_example.rb +21 -0
  9. data/lib/tk_paradise/examples/006_multiple_buttons.rb +16 -0
  10. data/lib/tk_paradise/examples/007_packing_example_in_tk.rb +28 -0
  11. data/lib/tk_paradise/examples/008_pig_latin_example.rb +70 -0
  12. data/lib/tk_paradise/examples/009_scrollbar_example.rb +44 -0
  13. data/lib/tk_paradise/examples/010_telnet_client.rb +106 -0
  14. data/lib/tk_paradise/examples/011_thermostat_example.rb +60 -0
  15. data/lib/tk_paradise/examples/012_tk_menu_example.rb +23 -0
  16. data/lib/tk_paradise/examples/013_tk_popup.rb +61 -0
  17. data/lib/tk_paradise/examples/014_tk_slider.rb +63 -0
  18. data/lib/tk_paradise/examples/015_choose_colour_example.rb +22 -0
  19. data/lib/tk_paradise/examples/016_spin_box_example.rb +28 -0
  20. data/lib/tk_paradise/examples/017_combo_box_example.rb +46 -0
  21. data/lib/tk_paradise/examples/018_tk_list_box_example.rb +18 -0
  22. data/lib/tk_paradise/examples/advanced/0001_example_showing_move_method.rb +32 -0
  23. data/lib/tk_paradise/tk_classes/root.rb +24 -0
  24. data/lib/tk_paradise/tk_paradise.rb +164 -0
  25. data/lib/tk_paradise/version/version.rb +19 -0
  26. data/lib/tk_paradise.rb +5 -0
  27. data/tk_paradise.gemspec +41 -0
  28. metadata +102 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 57e4a8df5ba60f4d91f8ca5ca47e5479a291f6234be90a1396f4e4b29c1712b3
4
+ data.tar.gz: eb0d691e920529f48a61ec739b1f63ca89e8b5adfb0518aaed788d45734c784d
5
+ SHA512:
6
+ metadata.gz: 30453d6c0479e4b51ca533e4b00c440eab792b01eb760545faf081bb1d00fd2fa6499508c8f84f6fb2fc216de6bc92cc84315af795e4129e68e2c94ecca17b62
7
+ data.tar.gz: 055f4da45f19d7d51bc5a39c2b0f20ff090b33ec7e75d686540e26b8259b241c6e386ba196b9d61f09b1681a8101c2bead8e2157a35532a8ec4ff340af5f8e28
data/doc/HINTS.md ADDED
@@ -0,0 +1,318 @@
1
+ ADD_RUBY_BADGE
2
+ ADD_TIME_STAMP
3
+
4
+ Specify width, height, then x-coordinate, then y-coordinate:
5
+
6
+ root.geometry('800x600+0+0')
7
+ root.geometry('250x150+0+0')
8
+ root.geometry("500x100") # Just width x height
9
+ root.geometry("800x500") # Just width x height
10
+ root.geometry("+300+300") # And this will only specify the x and y coordinates
11
+
12
+ Create a new root entry:
13
+
14
+ TITLE = 'This is my widget'
15
+ root = TkRoot.new { title TITLE }
16
+
17
+ Set the title of the root widget at a later point:
18
+
19
+ root.title('YO')
20
+
21
+ Set a minimal size of the root widget:
22
+
23
+ root.minsize(400, 200)
24
+
25
+ Make the root window invisible (so that e. g. only the menubar shows up):
26
+
27
+ root.withdraw
28
+
29
+ Disallow the root window from being resized:
30
+
31
+ Tk.root.resizable(false, false) # boolean value: (width, height)
32
+
33
+ Obtain the value of an entry:
34
+
35
+ use .get
36
+
37
+ Delete the content of an entry:
38
+
39
+ entry.delete(0,'end') # Weird that 'end' is used there.
40
+
41
+ Set the value of an entry:
42
+
43
+ entry.insert(0, _)
44
+
45
+ # Note that I was unable to get this to work: entry.configure(text: 'Hey there')
46
+
47
+ Create an entry (entry tag):
48
+
49
+ @entry1 = TkEntry.new(outermost_frame, textvariable: @text1) {
50
+ font(MAIN_FONT)
51
+ }
52
+
53
+ Set the width of an entry:
54
+
55
+ entry.configure(width: 35) # Oddly enough I have no idea what this number stands for.
56
+
57
+ Set the background colour of an entry:
58
+
59
+ background 'steelblue'
60
+ root.configure(background: 'black')
61
+
62
+ Respond to key-events for entry:
63
+
64
+ entry.bind('Key', proc {|this_key|
65
+ e "This key was pressed: `#{this_key}`"
66
+ }, '%K')
67
+
68
+ Change an entry dynamically:
69
+
70
+ label = TkLabel.new(top) {
71
+ text 'Hello, World!'
72
+ }
73
+ TkButton.new(top) {
74
+ text "Cancel"
75
+ command proc {
76
+ label.configure('text'=>"Goodbye, Cruel World!")
77
+ }
78
+ pack('side'=>'right', 'padx'=>10, 'pady'=>10)
79
+ }
80
+
81
+ Now when the Cancel button is pressed, the text in the label
82
+ will change immediately from ``Hello, World!'' to ``Goodbye,
83
+ Cruel World!''
84
+
85
+ Create buttons:
86
+
87
+ Button.new(root, text: 'two')
88
+ TkButton.new(root, text: entry)
89
+ TkButton.new(root, text: 'is').grid("columnspan"=>3, "sticky"=>"ew")
90
+ TkButton.new(root, text: 'two').grid("row"=>1, "column"=>3, "columnspan"=>3)
91
+
92
+ Button is-clicked event (clicked callback):
93
+
94
+ command proc {
95
+ e 'Hello.'
96
+ }
97
+
98
+ Add the button to the main root:
99
+
100
+ button.pack
101
+
102
+ Create a new grid:
103
+
104
+ TkGrid.grid(buttons[0], buttons[1], buttons[2], columnspan: 2 )
105
+
106
+ Start the mainloop:
107
+
108
+ Tk.mainloop
109
+ Tk.run # Or this variant when the tk_paradise gem is used.
110
+
111
+ Specify font size:
112
+
113
+ root.option_add('*Font', '25')
114
+
115
+ Return the available fonts:
116
+
117
+ pp TkFont.names
118
+ # ["TkCaptionFont", "TkSmallCaptionFont", "TkTooltipFont",
119
+ # "TkFixedFont", "TkHeadingFont", "TkMenuFont", "TkIconFont",
120
+ # "TkTextFont", "TkDefaultFont"]
121
+
122
+ 1 TkDefaultFont: The default for all GUI items not otherwise specified.
123
+ 2 TkTextFont: Used for entry widgets, listboxes, etc.
124
+ 3 TkFixedFont: A standard fixed-width font.
125
+ 4 TkMenuFont: The font used for menu items.
126
+ 5 TkHeadingFont: The font typically used for column headings in lists and tables.
127
+ 6 TkCaptionFont: A font for window and dialog caption bars.
128
+ 7 TkSmallCaptionFont: A smaller caption font for subwindows or tool dialogs
129
+ 8 TkIconFont: A font for icon captions.
130
+ 9 TkTooltipFont: A font for tooltips.
131
+
132
+ Specify a font to use (font tag):
133
+
134
+ font = TkFont.new(family: 'Helvetica', size: 20, weight: 'bold')
135
+ TkLabel.new(root) { text 'Attention!'; font TkCaptionFont }
136
+
137
+ MONOSPACED_FONT = TkFont.new(family: 'Hack', size: 22, weight: 'bold')
138
+
139
+ Create a new tk-variable:
140
+
141
+ text1 = TkVariable.new
142
+
143
+ Note that TkVariable implements #to_a, which can be used to convert
144
+ its value into an Array.
145
+
146
+ How to create a label (text):
147
+
148
+ label = TkLabel.new(root) {
149
+ textvariable
150
+ borderwidth 5
151
+ font use_this_font
152
+ foreground 'red' # The foreground colour to use.
153
+ relief 'groove'
154
+ pack(side: 'right', padx: '50', pady: '50')
155
+ }
156
+
157
+ Draw on a canvas:
158
+
159
+ canvas = TkCanvas.new(root)
160
+
161
+ Multiple spanning in a grid:
162
+
163
+ .grid(row: 1, column: 3, columnspan: 3)
164
+
165
+ How to let the button perform an action:
166
+
167
+ button = Button.new(root, text: 'foobar) {
168
+ command proc {
169
+ puts 'I am saying '+::Colours.sfancy('hello world')+'!'
170
+ }
171
+ }
172
+
173
+ Padding in tk:
174
+
175
+ Use padx and pady for a grid. Example:
176
+
177
+ .grid(row: 1, column: 3, columnspan: 3, padx: 5, pady: 5)
178
+
179
+ Pack a tk-label:
180
+
181
+ TkLabel.new(root) {
182
+ text 'Hello, World!'
183
+ pack { padx 25 ; pady 25; side 'left' }
184
+ }
185
+
186
+ Make use of a scrollbar (scrollbar tag):
187
+
188
+ scrollbar = TkScrollbar.new(root).pack(side: :right, fill: :y)
189
+
190
+ command proc{|idx|
191
+ list.yview *idx
192
+ }
193
+
194
+ Combo box widget:
195
+
196
+ list = TkListbox.new(frame).pack
197
+ list.insert("end", "/home")
198
+ list.insert("end", "/etc/hosts")
199
+
200
+ Or alternatively:
201
+ n = TkVariable.new
202
+ combo_box = TkCombobox.new(
203
+ root,
204
+ width: 30,
205
+ font: MONOSPACED_FONT,
206
+ textvariable: n
207
+ )
208
+ combo_box.values(%w(
209
+ aa bb cc dd ee ff gg hh ii jj kk ll mm nn oo pp qq rr ss tt uu
210
+ ))
211
+ combo_box.grid(column: 0, row: 6)
212
+
213
+ How to select the current value of such a combo-box:
214
+
215
+ combo_box.current = 3 # This uses the fourth element.
216
+
217
+ Query / Obtain values:
218
+
219
+ This is done via the method .cget().
220
+
221
+ b.cget('text') # "OK"
222
+ b.cget('justify') # "left"
223
+ b.cget('border') # 5
224
+
225
+ Events in ruby-tk in general need to make use of .bind, in order
226
+ to tie an event to a widget.
227
+
228
+ mouse-over event:
229
+
230
+ image1 = TkPhotoImage.new { file "img1.gif" }
231
+ b = TkButton.new(@root) {
232
+ image image1
233
+ command proc { doit }
234
+ }
235
+ b.bind("Enter") { b.configure(image: image2) }
236
+ b.bind("Leave") { b.configure(image: image1) }
237
+
238
+ The configure method (configure tag):
239
+
240
+ Every widget in tk supports the .configure() method.
241
+ button.configure(text: "Goodbye, Cruel World!")
242
+
243
+ Creating images (image tag, img tag):
244
+
245
+ image = TkPhotoImage.new(file: 'foobar.png', height: 82)
246
+
247
+ Create some text:
248
+
249
+ text = TkText.new(root) { width 20; height 5 }.pack(side: :left)
250
+
251
+ Append onto the text-widget:
252
+
253
+ text.insert('end', 'Left in canvas')
254
+
255
+ Create a frame:
256
+
257
+ frame = TkFrame(root, highlightbackground: "black",
258
+ highlightthickness: 2,
259
+ bd: 0)
260
+ Add a button to that frame:
261
+
262
+ button = TkButton(frame, text: 'Submit', fg: 'black',
263
+ bg: 'yellow', font: (("Times New Roman"),15))
264
+
265
+ bttn.pack()
266
+
267
+ Set the width of a border around a button:
268
+
269
+ borderwidth 3
270
+
271
+ Set the style of a border:
272
+
273
+ Possible values include:
274
+
275
+ flat
276
+
277
+ Use it like this:
278
+
279
+ relief 'flat'
280
+ relief 'ridge'
281
+ relief 'sunken'
282
+
283
+ How to use TkMessage:
284
+
285
+ TkMessage.new(root) {
286
+
287
+ Start in the top left corner:
288
+
289
+ root.geometry('250x150+0+0')
290
+
291
+ How to use an open-file dialog:
292
+
293
+ Tk.getOpenFile
294
+
295
+ How to create a spin-button in ruby-tk (also called a spin-box):
296
+
297
+ TkSpinbox.new(root) {
298
+ ...Standard Options...
299
+ ...Widget-specific Options...
300
+ }
301
+
302
+ Such as:
303
+
304
+ TkSpinbox.new(root) {
305
+ to 250
306
+ from 0
307
+ increment 5
308
+ pack(side: 'left', padx: '50', pady: '50')
309
+ }
310
+
311
+ To center it, use:
312
+
313
+ justify :center
314
+
315
+ Useful links:
316
+
317
+ https://tkdocs.com/tutorial/text.html
318
+ https://www.tutorialspoint.com/ruby/ruby_tk_dialogbox.htm
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'tk_paradise/base/base.rb'
6
+ # =========================================================================== #
7
+ module Tk
8
+
9
+ class Base # === Tk::Base
10
+
11
+ require 'colours'
12
+ include Colours
13
+
14
+ # ========================================================================= #
15
+ # === initialize
16
+ # ========================================================================= #
17
+ def initialize(
18
+ i = ARGV
19
+ )
20
+ set_commandline_arguments(i)
21
+ reset
22
+ end
23
+
24
+ # ========================================================================= #
25
+ # === reset (reset tag)
26
+ # ========================================================================= #
27
+ def reset
28
+ # ======================================================================= #
29
+ # === @internal_hash
30
+ # ======================================================================= #
31
+ @internal_hash = {}
32
+ end
33
+
34
+ # ========================================================================= #
35
+ # === set_commandline_arguments
36
+ # ========================================================================= #
37
+ def set_commandline_arguments(i = '')
38
+ i = [i].flatten.compact
39
+ @commandline_arguments = i
40
+ end
41
+
42
+ # ========================================================================= #
43
+ # === commandline_arguments?
44
+ # ========================================================================= #
45
+ def commandline_arguments?
46
+ @commandline_arguments
47
+ end
48
+
49
+ # ========================================================================= #
50
+ # === first_argument?
51
+ # ========================================================================= #
52
+ def first_argument?
53
+ @commandline_arguments.first
54
+ end; alias first? first_argument? # === first?
55
+
56
+ # ========================================================================= #
57
+ # === tk_variable
58
+ # ========================================================================= #
59
+ def tk_variable
60
+ TkVariable.new
61
+ end
62
+
63
+ end; end
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ require 'tk'
6
+
7
+ root = TkRoot.new
8
+ root.title = 'Window'
9
+ root.geometry('800x600+0+0')
10
+ button_click = Proc.new {
11
+ Tk.getOpenFile
12
+ }
13
+
14
+ button = TkButton.new(root) {
15
+ text 'button'
16
+ pack(side: :left, padx: "50", pady: "50")
17
+ }
18
+
19
+ button.command = button_click
20
+
21
+ Tk.mainloop
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ require 'tk'
6
+
7
+ root = TkRoot.new { title 'Click to draw a tiny box' }
8
+ TkLabel.new(root) { text 'Attention!'; font TkCaptionFont }
9
+ canvas = TkCanvas.new(root)
10
+ canvas.pack
11
+ canvas.bind('1', proc { |e|
12
+ p "#{e.x}, #{e.y}"
13
+ TkcRectangle.new(canvas, e.x,e.y,e.x-5, e.y-5)
14
+ })
15
+ root.bind('Any-Key-d',
16
+ proc { |event|
17
+ p "#{event.x}, #{event.y}"
18
+ TkcRectangle.new(canvas, event.x, event.y, event.x-5, event.y-5)
19
+ }
20
+ )
21
+ Tk.mainloop
22
+ # rb draw_tiny_box.rb
@@ -0,0 +1,82 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ require 'tk'
6
+ root = TkRoot.new { title 'Fun with Cursors'}
7
+ # =========================================================================== #
8
+ # Specify the Root Geometry
9
+ # =========================================================================== #
10
+ root.geometry '1250x1000+0+0'
11
+
12
+ TkMessage.new(root) { x='bottom_side';text x;background 'green';cursor x}.pack('side'=>'right', padx: 4, 'padx'=>2)
13
+ TkMessage.new(root) { x='bottom_side';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
14
+ TkMessage.new(root) { x='box_spiral';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
15
+ TkMessage.new(root) { x='center_ptr';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
16
+ TkMessage.new(root) { x='circle';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
17
+ TkMessage.new(root) { x='clock';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
18
+ TkMessage.new(root) { x='coffee_mug';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
19
+ TkMessage.new(root) { x='cross';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
20
+ TkMessage.new(root) { x='cross_reverse';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
21
+ TkMessage.new(root) { x='crosshair';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
22
+ TkMessage.new(root) { x='diamond_cross';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
23
+ TkMessage.new(root) { x='dot';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
24
+ TkMessage.new(root) { x='dotbox';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
25
+ TkMessage.new(root) { x='double_arrow';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
26
+ TkMessage.new(root) { x='draft_large';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
27
+ TkMessage.new(root) { x='draft_small';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
28
+ TkMessage.new(root) { x='draped_box';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
29
+ TkMessage.new(root) { x='exchange';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
30
+ TkMessage.new(root) { x='bottom_side';text x;background 'green';cursor x}.pack('side'=>'right', padx: 4, 'padx'=>2)
31
+ TkMessage.new(root) { x='bottom_side';text x;background 'green';cursor x}.pack('side'=>'right', padx: 4, 'padx'=>2)
32
+ TkMessage.new(root) { x='bottom_side';text x;background 'green';cursor x}.pack('side'=>'right', padx: 4, 'padx'=>2)
33
+ TkMessage.new(root) { x='bottom_side';text x;background 'green';cursor x}.pack('side'=>'right', padx: 4, 'padx'=>2)
34
+ TkMessage.new(root) { x='hand2';text x;background 'green';cursor x}.pack('side'=>'right', padx: 4, 'padx'=>2)
35
+ TkMessage.new(root) { x='heart';text x;background 'green';cursor x}.pack('side'=>'right', padx: 4, 'padx'=>2)
36
+ TkMessage.new(root) { x='icon';text x;background 'green';cursor x}.pack('side'=>'right', padx: 4, 'padx'=>2)
37
+ TkMessage.new(root) { x='iron_cross';text x;background 'green';cursor x}.pack('side'=>'right', padx: 4, 'padx'=>2)
38
+ TkMessage.new(root) { x='left_ptr';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
39
+ TkMessage.new(root) { x='left_side';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
40
+ TkMessage.new(root) { x='left_tee';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
41
+ TkMessage.new(root) { x='leftbutton';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
42
+ TkMessage.new(root) { x='ll_angle';text x;background 'green';cursor x}.pack('side'=>'right', padx: 4, 'padx'=>2)
43
+ TkMessage.new(root) { x='lr_angle';text x;background 'green';cursor x}.pack('side'=>'right', padx: 4, 'padx'=>2)
44
+ TkMessage.new(root) { x='man';text x;background 'green';cursor x}.pack('side'=>'right', padx: 4, 'padx'=>2)
45
+ TkMessage.new(root) { x='middlebutton';text x;background 'green';cursor x}.pack('side'=>'right', padx: 4, 'padx'=>2)
46
+ TkMessage.new(root) { x='mouse';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
47
+ TkMessage.new(root) { x='pencil';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
48
+ TkMessage.new(root) { x='pirate';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
49
+ TkMessage.new(root) { x='plus';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
50
+ TkMessage.new(root) { x='question_arrow';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
51
+ TkMessage.new(root) { x='right_ptr';text x;background 'green';cursor x}.pack('side'=>'bottom', padx: 4, 'padx'=>2)
52
+ TkMessage.new(root) { x='right_side';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
53
+ TkMessage.new(root) { x='right_tee';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
54
+ TkMessage.new(root) { x='rightbutton';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
55
+ TkMessage.new(root) { x='rtl_logo';text x;background 'green';cursor x}.pack('side'=>'bottom', padx: 4, 'padx'=>2)
56
+ TkMessage.new(root) { x='sailboat';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
57
+ TkMessage.new(root) { x='sb_down_arrow';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
58
+ TkMessage.new(root) { x='sb_h_double_arrow';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
59
+ TkMessage.new(root) { x='sb_left_arrow';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
60
+ TkMessage.new(root) { x='sb_right_arrow';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
61
+ TkMessage.new(root) { x='sb_up_arrow';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
62
+ TkMessage.new(root) { x='sb_v_double_arrow';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
63
+ TkMessage.new(root) { x='shuttle';text x;background 'green';cursor x}.pack('side'=>'top', padx: 4, 'padx'=>2)
64
+ TkMessage.new(root) { x='sizing';text x;background 'green';cursor x}.pack('side'=>'right', padx: 4, 'padx'=>2)
65
+ TkMessage.new(root) { x='spider';text x;background 'green';cursor x}.pack('side'=>'left', padx: 4, 'padx'=>2)
66
+ TkMessage.new(root) { x='spraycan';text x;background 'green';cursor x}.pack('side'=>'left', padx: 4, 'padx'=>2)
67
+ TkMessage.new(root) { x='star';text x;background 'green';cursor x}.pack('side'=>'left', padx: 4, 'padx'=>2)
68
+ TkMessage.new(root) { x='target';text x;background 'green';cursor x}.pack('side'=>'left', padx: 4, 'padx'=>2)
69
+ TkMessage.new(root) { x='tcross';text x;background 'green';cursor x}.pack('side'=>'left', padx: 4, 'padx'=>2)
70
+ TkMessage.new(root) { x='top_left_arrow';text x;background 'green';cursor x}.pack('side'=>'left', padx: 4, 'padx'=>2)
71
+ TkMessage.new(root) { x='top_left_corner';text x;background 'green';cursor x}.pack('side'=>'left', padx: 4, 'padx'=>2)
72
+ TkMessage.new(root) { x='top_right_corner';text x;background 'green';cursor x}.pack('side'=>'left', padx: 4, 'padx'=>2)
73
+ TkMessage.new(root) { x='top_side';text x;background 'green';cursor x}.pack('side'=>'left', padx: 4, 'padx'=>2)
74
+ TkMessage.new(root) { x='top_tee';text x;background 'green';cursor x}.pack('side'=>'left', padx: 4, 'padx'=>2)
75
+ TkMessage.new(root) { x='trek';text x;background 'green';cursor x}.pack('side'=>'left', padx: 4, 'padx'=>2)
76
+ TkMessage.new(root) { x='ul_angle';text x;background 'green';cursor x}.pack('side'=>'left', padx: 4, 'padx'=>2)
77
+ TkMessage.new(root) { x='umbrella';text x;background 'green';cursor x}.pack('side'=>'left', padx: 4, 'padx'=>2)
78
+ TkMessage.new(root) { x='ur_angle';text x;background 'green';cursor x}.pack('side'=>'left', padx: 4, 'padx'=>2)
79
+ TkMessage.new(root) { x='watch';text x;background 'green';cursor x}.pack('side'=>'left', padx: 4, 'padx'=>2)
80
+ TkMessage.new(root) { x='xterm';text x;background 'green';cursor x}.pack('side'=>'left', padx: 4, 'padx'=>2)
81
+ Tk.mainloop
82
+ # rb fun_with_cursors.rb
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ require 'tk_paradise'
6
+ require 'colours/autoinclude'
7
+
8
+ root = TkRoot.new() { title 'Hello, world!' }
9
+
10
+ TkLabel.new(root) {
11
+ text 'Hello, World!'
12
+ pack { padx 25 ; pady 25; side 'left' }
13
+ }
14
+ # Add the hello world button next:
15
+ button = TkButton.new(root) {
16
+ text 'Hello, World!'
17
+ command proc {
18
+ e 'I am saying '+sfancy('hello world')+'!'
19
+ }
20
+ }
21
+ button.pack
22
+ Tk.mainloop
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ require 'tk'
6
+
7
+ alias e puts
8
+
9
+ USE_THIS_FONT = TkFont.new(family: 'Helvetica', size: 20, weight: 'bold')
10
+
11
+ root = TkRoot.new
12
+ root.geometry('800x600+0+0')
13
+ entry = TkEntry.new(root) {
14
+ font USE_THIS_FONT
15
+ pack
16
+ }
17
+ entry.bind('Key', proc {|this_key|
18
+ e "This key was pressed: `#{this_key}`"
19
+ }, '%K')
20
+
21
+ Tk.mainloop
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ require 'tk'
6
+
7
+ TITLE = 'Several buttons'
8
+ root = TkRoot.new { title TITLE }
9
+ root.geometry('550x450+10+10')
10
+ buttons = %w( one and one ).map { |entry|
11
+ TkButton.new(root, text: entry)
12
+ }
13
+ TkGrid.grid(buttons[0], buttons[1], buttons[2], columnspan: 2 )
14
+ TkButton.new(root, text: 'is').grid(columnspan: 3, sticky: 'ew')
15
+ TkButton.new(root, text: 'two', width: 50).grid("row"=>1, "column"=>3, "columnspan"=>3)
16
+ Tk.mainloop
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ require 'tk_paradise'
6
+
7
+ include Tk
8
+
9
+ IMAGE = '/home/x/DATA/images/HUE2.gif'
10
+
11
+ root = TkRoot.new() { title 'Packing Example' }
12
+
13
+ button = TkButton.new(root) { text 'First, rightmost' }
14
+ button.pack('side'=>'right', 'fill'=>'y')
15
+
16
+ entry = TkEntry.new(root).pack('side'=>'top', 'fill'=>'x')
17
+ entry.insert(0, 'Entry on the top')
18
+
19
+ label = tk_label('to the right', root) { :on_right }
20
+
21
+ our_image = tk_image(image, height: 50)
22
+ img_label = TkLabel.new(root) { image(our_image) }.pack('anchor'=>'e')
23
+
24
+ text = TkText.new(root) { width 20; height 5 }.pack('side'=>'left')
25
+ text.insert('end', 'Left in canvas')
26
+
27
+ tk_label('Message in the Bottom', root) { :on_bottom }
28
+ Tk.run
@@ -0,0 +1,70 @@
1
+ require 'tk'
2
+
3
+ class PigBox
4
+
5
+ # ========================================================================= #
6
+ # === PADDING_TO_USE
7
+ # ========================================================================= #
8
+ PADDING_TO_USE = {
9
+ padx: 10,
10
+ pady: 10
11
+ }
12
+
13
+ # ========================================================================= #
14
+ # === initialize
15
+ # ========================================================================= #
16
+ def initialize
17
+ use_this_callback = proc { show_pig }
18
+ root = TkRoot.new { title 'Pig' }
19
+ top = TkFrame.new(root)
20
+ TkLabel.new(top) {
21
+ text 'Enter Text:'
22
+ pack(PADDING_TO_USE)
23
+ }
24
+ @text = TkVariable.new
25
+ @entry = TkEntry.new(top, textvariable: @text)
26
+ @entry.pack(PADDING_TO_USE)
27
+ TkButton.new(top) {
28
+ text 'Pig It'
29
+ command use_this_callback
30
+ pack PADDING_TO_USE
31
+ }
32
+ TkButton.new(top) {
33
+ text 'Exit'
34
+ command {proc exit}
35
+ pack PADDING_TO_USE
36
+ }
37
+ top.pack(fill: 'both', side: 'top')
38
+ end
39
+
40
+ # ========================================================================= #
41
+ # === pig
42
+ # ========================================================================= #
43
+ def pig(word)
44
+ leadingCap = word =~ /^A-Z/
45
+ word.downcase!
46
+ res =
47
+ case word
48
+ when /^aeiouy/
49
+ "#{word}way"
50
+ when /^([^aeiouy]+)(.*)/
51
+ $2+$1+"ay"
52
+ else
53
+ word
54
+ end
55
+ leadingCap ? res.capitalize : res
56
+ end
57
+
58
+ # ========================================================================= #
59
+ # === show_pig
60
+ # ========================================================================= #
61
+ def show_pig
62
+ @text.value = @text.value.split.collect{|w| pig(w)}.join(' ')
63
+ end
64
+
65
+ end
66
+
67
+ if __FILE__ == $PROGRAM_NAME
68
+ PigBox.new
69
+ Tk.mainloop
70
+ end