1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# -*- coding: utf-8 -*-
#
# spin.rb --
#
# This demonstration script creates several spinbox widgets.
#
# based on Tcl/Tk8.4.4 widget demos
if defined?($spin_demo) && $spin_demo
$spin_demo.destroy
$spin_demo = nil
end
$spin_demo = TkToplevel.new {|w|
title("Spinbox Demonstration")
iconname("spin")
positionWindow(w)
}
base_frame = TkFrame.new($spin_demo).pack(:fill=>:both, :expand=>true)
TkLabel.new(base_frame,
:font=>$font, :wraplength=>'5i', :justify=>:left,
:text=><<EOL).pack(:side=>:top)
ä¸ã«ã¯ï¼ç¨®é¡ã®ã¹ãã³ããã¯ã¹ã表示ããã¦ãã¾ãã
ããããããã¦ã¹ã§é¸æãã¦æåãå
¥åãããã¨ãã§ãã¾ãã
ç·¨éæä½ã¨ãã¦ã¯ãEmacs å½¢å¼ã®å¤ãã«å ãã¦ãä¸è¬çãª
Motif å½¢å¼ã®ãã¼æä½ããµãã¼ãããã¦ãã¾ãããã¨ãã°ã
Backspace 㨠Control-h ã¨ã¯å
¥åã«ã¼ã½ã«ã®å·¦å´ã®æåã
åé¤ããDelete 㨠Control-d ã¨ã¯å³å´ã®æåãåé¤ãã¾ãã
å
¥åæ ã®é·ããè¶ãããããªé·ãæååãå
¥åããå ´åã«ã¯ã
ãã¦ã¹ã®ãã¿ã³ï¼ãæ¼ãã¦ãã©ãã°ãããã¨ã§ãå
¥åæåå
ãã¹ãã£ã³ãããã¨ãå¯è½ã§ãã
ãªããæåã®ã¹ãã³ããã¯ã¹ã¯ãæ´æ°å¤ã¨ã¿ãªããããããª
æååããå
¥åã許ãããªããã¨ã«æ³¨æãã¦ãã ãããã¾ãã
ï¼çªç®ã®ã¹ãã³ããã¯ã¹ã§é¸æåè£ã«ç¾ããã®ã¯ãªã¼ã¹ãã©
ãªã¢ã®é½å¸åã®ãªã¹ãã¨ãªã£ã¦ãã¾ãã
ããããªãã使ã£ã¦ãã Ruby ã«ãªã³ã¯ããã¦ãã Tk ã©ã¤
ãã©ãªã spinbox ã¦ã£ã¸ã§ãããå®è£
ãã¦ããªãå ´åããã®
ãã¢ã¯ãã¾ãåããªãã¯ãã§ãããã®å ´åã«ã¯ spinbox ã¦ã£
ã¸ã§ãããå®è£
ããã¦ãããããªããæ°ãããã¼ã¸ã§ã³ã® Tk
ãçµã¿åããã¦è©¦ãããã«ãã¦ãã ããã
EOL
TkFrame.new(base_frame){|f|
pack(:side=>:bottom, :fill=>:x, :pady=>'2m')
TkButton.new(f, :text=>'éãã', :width=>15, :command=>proc{
$spin_demo.destroy
$spin_demo = nil
}).pack(:side=>:left, :expand=>true)
TkButton.new(f, :text=>'ã³ã¼ãåç
§', :width=>15, :command=>proc{
showCode 'spin'
}).pack(:side=>:left, :expand=>true)
}
australianCities = [
'Canberra', 'Sydney', 'Melbourne', 'Perth', 'Adelaide',
'Brisbane', 'Hobart', 'Darwin', 'Alice Springs'
]
[
TkSpinbox.new(base_frame, :from=>1, :to=>10, :width=>10, :validate=>:key,
:validatecommand=>[
proc{|s| s == '' || /^[+-]?\d+$/ =~ s }, '%P'
]),
TkSpinbox.new(base_frame, :from=>0, :to=>3, :increment=>0.5,
:format=>'%05.2f', :width=>10),
TkSpinbox.new(base_frame, :values=>australianCities, :width=>10)
].each{|sbox| sbox.pack(:side=>:top, :pady=>5, :padx=>10)}
|